Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MiniMagickの型を生成したい
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
a_fujisaki
August 01, 2024
Programming
0
130
MiniMagickの型を生成したい
a_fujisaki
August 01, 2024
Tweet
Share
More Decks by a_fujisaki
See All by a_fujisaki
自作マクロと型生成
aki19035vc
0
33
rails newと同時に型を書く
aki19035vc
6
1.1k
“Rails × 型”での2年間を振り返る
aki19035vc
2
1.2k
rbs-inlineを使ってみた
aki19035vc
0
900
Emacs × LSP × Steep
aki19035vc
0
260
最近追加した型の紹介とその振り返り
aki19035vc
0
760
Other Decks in Programming
See All in Programming
Fluid Templating in TYPO3 14
s2b
0
110
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
130
Deno Tunnel を使ってみた話
kamekyame
0
350
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
5.8k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
550
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
260
AtCoder Conference 2025
shindannin
0
990
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
180
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
160
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
500
Graviton と Nitro と私
maroon1st
0
170
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
380
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
150
How GitHub (no longer) Works
holman
316
140k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
130
Building Flexible Design Systems
yeseniaperezcruz
330
40k
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
160
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
130
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Transcript
MiniMagickの型を生成したい Roppongi.rb#21 2024-08-01 @aki19035vc
自己紹介 ❏ 藤崎 亮人 ❏ @aki19035vc ❏ 所属: イタンジ株式会社 ❏
バックエンドエンジニア ❏ 不動産物件データベースの基盤開発 ❏ 学生の頃からEmacs使ってます
今日話すこと ❏ MiniMagickの型の話 ❏ MiniMagickの基本的な型の追加と困ったこと ❏ ImageMagickのドキュメントから型を生成するGemの紹介 ❏ https://github.com/aki19035vc/rbs_mini_magick ※
前回の Roppongi.rb#20 で話した内容の続き ※ 型についての基本的な解説はしません
なぜMiniMagickに型をつけるのか ❏ 業務で書いているRailsアプリケーションでは型をほぼ100%書いている ❏ MiniMagickの型がなかったので、必要な部分は自前で書いていた ❏ 他のRailsアプリケーションでも使いたい事もある ❏ せっかくなのでコミュニティに還元していきたい
そもそもMiniMagickとは ❏ ImageMagickという画像を扱うソフトウェアのRubyバインディング ❏ 画像をリサイズしたりフォーマットを変換したりできる $ magick mogrify -resize 100x100
-format png -write output.png input.jpg require "mini_magick" image = MiniMagick::Image.open("input.jpg") image.resize "100x100" image.format "png" image.write "output.png"
MiniMagickの基本的な型を追加した ❏ MiniMagickのソースコードを読んで型を書く ❏ 人力型推論なので意外と大変 ❏ gem_rbs_collectionにPRを出す (自分でマージできる) ❏ 4.13:
https://github.com/ruby/gem_rbs_collection/pull/616 ❏ 5.0 : https://github.com/ruby/gem_rbs_collection/pull/629
困ったこと ❏ method_missing で黒魔術してる ❏ ImageMagickのコマンドを作るDSLが提供されているイメージ ❏ 使用可能なオプションが何百と存在するため、それら全てをメソッドとして定義するのは大 変 module
MiniMagick class Tool def method_missing(name, *args) option = "-#{name.to_s.tr('_', '-')}" self << option self.merge!(args) self end end end image.resize "100x100" image.format "png" image.write "output.png" #=> これらのメソッドは定義されていない
ドキュメントから型を生成する Gemを作った ❏ プロジェクトのsigディレクトリにMiniMagickの型を出力する ❏ 内部的にはImageMagickのhelpオプションで出力されるusageを使用 している ❏ インストールされているImageMagickのバージョンで利用できる オプションに応じた型を生成できる
(はず) $ bundle exec rbs-mini-magick generate https://github.com/aki19035vc/rbs_mini_magick
None
今後やりたいこと ❏ MiniMagickの5系以外のバージョンへの対応 ❏ 今はMiniMagick 5.0 しか対応していない (5.0は最近出たばかり) ❏ 最低でも4.13には対応したい
❏ 複数バージョンに対応できるようには作ってはある ❏ ImageMagickの7.1 系以外でも正しく動くことを確認 ❏ 今はImageMagick 7.1 でした動作確認をしていない ❏ 最低でも7.0では動くことを確認したい (6.9は気が向いたら) ❏ 業務で使用しているRailsアプリケーションの型検査で使ってみる