Class: Poniard::ControllerSource::Response
- Inherits:
-
Struct
- Object
- Struct
- Poniard::ControllerSource::Response
- Defined in:
- lib/poniard/controller_source.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#injector ⇒ Object
Returns the value of attribute injector.
Instance Method Summary collapse
- #default(ivars) ⇒ Object
- #redirect_to(path, *args) ⇒ Object
- #redirect_to_action(action) ⇒ Object
- #render(*args) ⇒ Object
- #render_action(action, ivars = {}) ⇒ Object
- #respond_with(klass, *args) ⇒ Object
- #send_data(*args) ⇒ Object
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller
3 4 5 |
# File 'lib/poniard/controller_source.rb', line 3 def controller @controller end |
#injector ⇒ Object
Returns the value of attribute injector
3 4 5 |
# File 'lib/poniard/controller_source.rb', line 3 def injector @injector end |
Instance Method Details
#default(ivars) ⇒ Object
40 41 42 43 44 |
# File 'lib/poniard/controller_source.rb', line 40 def default(ivars) ivars.each do |name, val| controller.instance_variable_set("@#{name}", val) end end |
#redirect_to(path, *args) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/poniard/controller_source.rb', line 4 def redirect_to(path, *args) unless path.to_s.ends_with?('_url') path = "#{path}_path" end controller.redirect_to(controller.send(path, *args)) end |
#redirect_to_action(action) ⇒ Object
12 13 14 |
# File 'lib/poniard/controller_source.rb', line 12 def redirect_to_action(action) controller.redirect_to action: action end |
#render(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/poniard/controller_source.rb', line 20 def render(*args) opts = args.last if opts.is_a?(Hash) ivars = opts.delete(:ivars) headers = opts.delete(:headers) end ivars ||= {} headers ||= {} ivars.each do |name, val| controller.instance_variable_set("@#{name}", val) end headers.each do |name, val| controller.headers[name] = val end controller.render *args end |
#render_action(action, ivars = {}) ⇒ Object
16 17 18 |
# File 'lib/poniard/controller_source.rb', line 16 def render_action(action, ivars = {}) render action: action, ivars: ivars end |
#respond_with(klass, *args) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/poniard/controller_source.rb', line 46 def respond_with(klass, *args) obj = klass.new(*args) format = controller.request.format.symbol if obj.respond_to?(format) injector.dispatch obj.method(format) end end |
#send_data(*args) ⇒ Object
54 55 56 |
# File 'lib/poniard/controller_source.rb', line 54 def send_data(*args) controller.send_data(*args) end |