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.3k
ビッグデータと機械学習の狭間で -データエンジニアに求められる役割-
onunu
5
1.4k
Railsと考えるデータベースのインデックス戦略
onunu
4
1.8k
地球とSQL
onunu
2
640
Other Decks in Technology
See All in Technology
空間オーディオで過去の 自分(ゴースト)と競うランニング 〜HealthKitのルートを足音に変える実装〜
nao_randd
0
220
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
5
630
beyond jj: config & tools ecosystem
indirect
0
510
What the customer really needed
kawaguti
PRO
3
200
LTのテーマ どうきめてる?〜5つの型と私のやり方〜
yama3133
1
110
AI de Idea
kawaguti
PRO
2
120
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
Screen Lens - 今見てる画面を翻訳する
komagata
0
320
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
25
16k
AI に書かせたその API、 “信頼” できますか?
nagix
0
120
[2026-09-11]SREは誰のもの?運用エンジニアが始める 「SRE領域への越境」とチームの進化の軌跡 〜Road to NEXT CRE
tosite
0
290
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
234
19k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Navigating Weather and Climate Data
rabernat
0
520
Test your architecture with Archunit
thirion
2
2.4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
It's Worth the Effort
3n
188
29k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
How to make the Groovebox
asonas
2
2.4k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Testing 201, or: Great Expectations
jmmastey
46
8.3k
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の理解が深まる
ご静聴ありがとうございました!