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
150
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
400
Repository pattern in Swift
naoty
3
6.3k
Timepiece
naoty
0
3.5k
Contribution to Rails
naoty
0
4.3k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.1k
Report of DIYish programming activity
naoty
1
220
Qiita/Kobito vs ?
naoty
0
190
Other Decks in Programming
See All in Programming
テストコード書いてみませんか?
onopon
2
340
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
1.2k
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
960
快速入門可觀測性
blueswen
0
500
Flatt Security XSS Challenge 解答・解説
flatt_security
0
740
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
The Language of Interfaces
destraynor
155
24k
Optimising Largest Contentful Paint
csswizardry
33
3k
GraphQLとの向き合い方2022年版
quramy
44
13k
The Cult of Friendly URLs
andyhume
78
6.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
We Have a Design System, Now What?
morganepeng
51
7.3k
Docker and Python
trallard
43
3.2k
Optimizing for Happiness
mojombo
376
70k
Designing Experiences People Love
moore
139
23k
Done Done
chrislema
182
16k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
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༵