Class: Rebels::RailsAdapters::RequestResponseAdapter
- Inherits:
-
Object
- Object
- Rebels::RailsAdapters::RequestResponseAdapter
- Defined in:
- lib/rebels/rails_adapters/request_response_adapter.rb
Instance Method Summary collapse
-
#initialize(rails_adapter, rebel_app) ⇒ RequestResponseAdapter
constructor
A new instance of RequestResponseAdapter.
- #method_missing(meth, *args, &blk) ⇒ Object
Constructor Details
#initialize(rails_adapter, rebel_app) ⇒ RequestResponseAdapter
Returns a new instance of RequestResponseAdapter.
2 3 4 5 |
# File 'lib/rebels/rails_adapters/request_response_adapter.rb', line 2 def initialize(rails_adapter, rebel_app) @rails_adapter = rails_adapter @rebel_app = rebel_app end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rebels/rails_adapters/request_response_adapter.rb', line 7 def method_missing(meth, *args, &blk) controller = args.first req = Rebels::Values::Request.with(params: controller.params) response = @rebel_app.send(meth, req) # @rails_adapter # response.session.each do |k,v| # @controller.session[k] = v # end # response.template_vars.each do |k,v| # @controller.instance_variable_set("@#{k}".to_sym, v) # end ret = if response.redirect_path # args = Array(response.redirect_path) # meth = args.shift # redir_args = if args.last.is_a? Hash # args.pop # else # {} # end # @controller.redirect_to meth, redir_args elsif response.json @rails_adapter.render json: response.json, status: response.status elsif response.text # @controller.render text: response.text, status: response.status elsif response.template_name # @controller.render response.template_name, status: response.status, layout: response.layout elsif response.status @rails_adapter.head response.status else raise 'no good' + response.inspect end # Rails.logger.info("response: #{ret}") ret end |