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
130
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
390
Repository pattern in Swift
naoty
3
6.1k
Timepiece
naoty
0
3.4k
Contribution to Rails
naoty
0
4.2k
久々のRailsプロジェクトで導入した開発環境
naoty
2
1.1k
Report of DIYish programming activity
naoty
1
190
Qiita/Kobito vs ?
naoty
0
180
Other Decks in Programming
See All in Programming
Goのエラースタックトレースの歴史と今後
sonatard
7
1.3k
Anthropic Cookbook のおすすめレシピ
schroneko
7
950
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
560
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
780
Goのmultiple errorsについて (2024年4月版)
syumai
3
710
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
930
Netty Chicago Java User Group 2024-04-17
sullis
0
170
2 週間で Twitter Bot を作ってみた
contour_gara
0
380
Code Reviews
bkuhlmann
4
890
Snowflakeで眠ったデータを起こそう!
estie
0
120
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
180
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
331
56k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
40
4.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
How to train your dragon (web standard)
notwaldorf
73
5.2k
The Cult of Friendly URLs
andyhume
74
5.7k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.6k
Ruby is Unlike a Banana
tanoku
96
10k
Rails Girls Zürich Keynote
gr2m
91
13k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Building a Scalable Design System with Sketch
lauravandoore
456
32k
Building Your Own Lightsaber
phodgson
99
5.7k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
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༵