Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Railtieでpluginを作ろう!
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
onunu
August 24, 2017
Technology
620
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Railtieでpluginを作ろう!
Meguro.rb #6の発表資料です
onunu
August 24, 2017
More Decks by onunu
See All by onunu
othlotech
onunu
1
3.4k
ビッグデータと機械学習の狭間で -データエンジニアに求められる役割-
onunu
5
1.4k
Railsと考えるデータベースのインデックス戦略
onunu
4
1.8k
地球とSQL
onunu
2
650
Other Decks in Technology
See All in Technology
cdk deployとcdkd deploy、実際にデプロイして5倍速近くの差を実測した
yama3133
1
120
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
100
Snowflake でできることが増えたら、 ABAC が必要になった
kaeton
0
120
OneLakeをデータソースにした AI Search(Foundry IQ)の ライフサイクル管理
ryuseiiida
0
190
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
580
「作れる」と「リリースできる」の間にあったもの── PdMを外して見えた、PdMがやるべき仕事/Buildable ≠ Shippable: What Removing the PM Taught Me About the PM’s Job
yappli_developers
0
380
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
250
200人の配信コメント、 全部Jevが仕分けます 〜 マサカリガードを作ってみた 〜
katayamatg
1
440
推論基盤と Scale-Up Interconnect の現状と制約から俯瞰する技術動向
markunet
2
610
Flutter Widget Previewerで始めるUIプレビューとVRTの自動化
sakusaku3939
0
170
ポケモン対戦を自動で記録して振り返ろう
fufufukakaka
0
420
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
3
2.1k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
550
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
460
Building an army of robots
kneath
307
47k
Navigating Weather and Climate Data
rabernat
0
570
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
570
Agile that works and the tools we love
rasmusluckow
331
22k
Speed Design
sergeychernyshev
33
2.2k
For a Future-Friendly Web
brad_frost
184
11k
Transcript
Railtieで Rails pluginを 作ろう! In Meguro.rb #6 @onunu
Hello! おぬま りく@onunu SQLを書く仕事を してます:) Twitter: @onunu_ Github: onunu
1. Railtieってなに? (読み方がよくわかってない )
Railtieってなに? ◎ Rails公式のプラグイン機構 ◎ Railtieに基づいてコンポーネントを作ることで ◎ Railsの様々な処理を ◦ 変更したり ◦
拡張することができる Railties – Gluing the Engine to the Rails Railties is responsible for gluing all frameworks together. https://github.com/rails/rails/tree/master/railties
Railtieってなに? -Railtieでできること- ◎ 初期化処理(initializer) ◎ ジェネレータ(rails generate **) ◎ Rakeタスク
◎ 各種設定(config)
2. (よくわかってないけど) Railtieすごい
RailsはRailtieによって管理されている! よくある config/application.rb さまざまなgemのRailtie を requireしている
RailsはRailtieによって管理されている! Applicationクラスは Railtieクラスをもとに 作られている Rails::Application はRailtieのサブクラスだっ たんだなぁ Perfect Ruby on
Railsでの解説
3. Rails pluginを作ってみる
Rails pluginを作ってみる Railsのpluginとしてgemを作る時, 以下のいずれかになる ◎ Railtie <- 今回説明するやつ ◎ Engine
◎ MountableEngine 上から順にRails本体の処理に近い(雑)
Rails pluginを作ってみる -Railtieでinitializerを拡張する- 作成したpluginでRails::Railtieのサブクラスを作り ます。 サンプルでぼく謹製のgemを見てみます。 Rails::Railtieを継承したクラスで, Initializerメソッドに ブロックでコードを渡す
Rails pluginを作ってみる -Railtieでrakeも拡張する- RailtieでRakeタスクも定義できる rake_tasksメソッド内のブロックで Rakefileをloadすればよい
Rails pluginを作ってみる -Railtieでrakeも拡張する- Rails標準のタスクたちと 一緒に表示される
Rails pluginを作ってみる -Railtieでgeneratorも拡張する- generatorブロックで実行するコードを requireする
Rails pluginを作ってみる -Railtieでgeneratorも拡張する- generatorは rails generate generatorで生成される ものと同じものを作ればよい Generatorクラスに実装した メソッドが上から順に実行される
Rails pluginを作ってみる -Railtieでgeneratorも拡張する- generatorといいつつ、何をしてもよい ※ 何らかの引数を与える必要がある
4. まとめ
まとめ Rails pluginを作るにはRailtieを使いたい ◎ Railtieを使うと、 ◦ Railsの機能を活かしつつ ◦ Railsを拡張/変更できる
まとめ Engine/MountableEngineはなんだったの? ◎ よりアプリケーションに近い拡張ができる ◦ gemでありながらルーティングを追加したり ◦ Controller/Model/Viewなどを独自に追加できる ◎ このへんの話はまた今度:)
まとめ Railsで「うーん:(」ということがあったら Railtieを使えば 簡単に改善できるかも!
まとめ 宣伝 EncryptedSecretsを いい感じに扱うgemを作ったよ:) Leml - Merge your yaml to
rails secrets, and it encrypted only leaf - https://github.com/onunu/leml
Rails pluginを作れば Railsの理解が深まる
ご静聴ありがとうございました!