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
How to build gems for Rails
Search
naoty
January 31, 2013
Programming
1
180
How to build gems for Rails
naoty
January 31, 2013
Tweet
Share
More Decks by naoty
See All by naoty
Modular API Client
naoty
1
430
Repository pattern in Swift
naoty
3
6.4k
Timepiece
naoty
0
3.7k
Contribution to Rails
naoty
0
4.4k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.2k
Report of DIYish programming activity
naoty
1
290
Qiita/Kobito vs ?
naoty
0
210
Other Decks in Programming
See All in Programming
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
320
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
500
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
1k
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
5
960
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
540
Codex の「自走力」を高める
yorifuji
0
1.2k
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
180
受け入れテスト駆動開発(ATDD)×AI駆動開発 AI時代のATDDの取り組み方を考える
kztakasaki
2
570
CSC307 Lecture 13
javiergs
PRO
0
320
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
920
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
2.3k
文字コードの話
qnighy
44
17k
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
710
So, you think you're a good person
axbom
PRO
2
2k
Unsuck your backbone
ammeep
672
58k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Producing Creativity
orderedlist
PRO
348
40k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
540
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
70
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.5k
Google's AI Overviews - The New Search
badams
0
930
Transcript
How to build gems for Rails @naoty_k 131݄31༵
@naoty_k • Ruby on Rails (2010~) • Android (2012.5~) •
iOS (2012.10~) • vimmer!!! • curl http://cui-about.me/naoty 131݄31༵
Talk about... w1BSBNT*ORVJSFSʹ͍ͭͯ w3BJMTʹΈࠐΉ(FNʹඞཁͳͷ wιʔείʔυΛಡΜͰ্͍͘Ͱඞཁͳ 5JQT 131݄31༵
ParamsInquirer $ gem install params_inquirer $ irb 001 > require
‘params_inquirer’ 002 > params = ParamsInquirer::Parameters.new 003 > params[:name] = ‘naoty’ 004 > params[:name].naoty? => true 005 > params[:name].someone? => false 131݄31༵
ParamsInquirer on Rails def index if params[:status].accepted? # ... elsif
params[:status].rejected? # ... end end 131݄31༵
Railtie class Railtie < ::Rails::Railtie initializer ‘Initialize your gem’ do
ActiveSupport.on_load(:action_controller) do ::ActionController::Base.send :include, ParamsInquirer::ActionController::Base end end end 131݄31༵
action_controller/base.rb module ActionController class Base < Metal # ... ActiveSupport.run_load_hooks(:action_controller,
self) end end 131݄31༵
lib/params_inquirer.rb if defined?(Rails) require ‘params_inquirer/railtie’ else require ‘params_inquirer/parameters’ end 131݄31༵
ActiveSupport::Concern module M def self.included(self) base.extend ClassMethods scope :disabled, where(disabled:
true) end module ClassMethods # ... end end 131݄31༵
ActiveSupport::Concern module M extend ActiveSupport::Concern included do scope :disabled, where(disabled:
true) end module ClassMethods # ... end end 131݄31༵
ActiveSupport::Autoload autoload(:Hoge, ‘hoge’) # ‘hoge.rb‘͜ͷ࣌Ͱrequire͞Ε͍ͯͳ͍ p Hoge # ͜͜Ͱ‘hoge.rb’͕require͞ΕΔ extend
ActiceSupport::Autoload autoload :Fuga p Fuga # ͜͜Ͱ‘fuga.rb’͕require͞ΕΔ 131݄31༵