Module: Pakada::Dispatch::Controller::ClassMethods
- Defined in:
- lib/pakada/dispatch/controller.rb
Instance Method Summary collapse
- #action(name, opts = {}, &block) ⇒ Object
- #actions ⇒ Object
- #call(env) ⇒ Object
- #options(opts = {}) ⇒ Object
- #to_proc ⇒ Object
Instance Method Details
#action(name, opts = {}, &block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pakada/dispatch/controller.rb', line 77 def action(name, opts = {}, &block) if block actions[name] = { :block => block, :options => opts } else unless action = actions[name] raise ArgumentError, "Unknown action: #{name}" end = self..merge(action[:options]). merge(opts). merge(:action => name) proc {|env| self.new(env, .dup).process(&action[:block]).response.finish } end end |
#actions ⇒ Object
73 74 75 |
# File 'lib/pakada/dispatch/controller.rb', line 73 def actions @actions ||= {} end |
#call(env) ⇒ Object
106 107 108 109 110 |
# File 'lib/pakada/dispatch/controller.rb', line 106 def call(env) env["router.params"] ||= {} name = env["router.params"][:action] || env["REQUEST_METHOD"].downcase action(name.to_sym).call env end |
#options(opts = {}) ⇒ Object
98 99 100 |
# File 'lib/pakada/dispatch/controller.rb', line 98 def (opts = {}) (@options ||= {}).tap {|o| o.merge! opts } end |
#to_proc ⇒ Object
102 103 104 |
# File 'lib/pakada/dispatch/controller.rb', line 102 def to_proc method(:call).to_proc end |