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
a_fujisaki
August 01, 2024
Programming
0
120
MiniMagickの型を生成したい
a_fujisaki
August 01, 2024
Tweet
Share
More Decks by a_fujisaki
See All by a_fujisaki
rails newと同時に型を書く
aki19035vc
6
990
“Rails × 型”での2年間を振り返る
aki19035vc
2
1.1k
rbs-inlineを使ってみた
aki19035vc
0
770
Emacs × LSP × Steep
aki19035vc
0
200
最近追加した型の紹介とその振り返り
aki19035vc
0
620
Other Decks in Programming
See All in Programming
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
400
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
300
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
520
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
200
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
780
AI Agent 時代のソフトウェア開発を支える AWS Cloud Development Kit (CDK)
konokenj
2
210
AIともっと楽するE2Eテスト
myohei
7
2.8k
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
チームで開発し事業を加速するための"良い"設計の考え方 @ サポーターズCoLab 2025-07-08
agatan
1
440
“いい感じ“な定量評価を求めて - Four Keysとアウトカムの間の探求 -
nealle
2
11k
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
860
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
640
Featured
See All Featured
BBQ
matthewcrist
89
9.7k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
4 Signs Your Business is Dying
shpigford
184
22k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
How STYLIGHT went responsive
nonsquared
100
5.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
A Modern Web Designer's Workflow
chriscoyier
695
190k
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アプリケーションの型検査で使ってみる