Class: SmartAdapters::Delegator
- Inherits:
-
Object
- Object
- SmartAdapters::Delegator
- Defined in:
- lib/smart_adapters/delegator.rb
Constant Summary collapse
- FORMATS =
List of formats supported by SmartAdapters
%i[json html js xml text csv]
Instance Attribute Summary collapse
-
#manager ⇒ string
readonly
Return the controller requested.
Instance Method Summary collapse
-
#action ⇒ string
Return the action requested by the manager.
-
#api? ⇒ Boolean
Check if it is an API request.
-
#initialize(manager, request) ⇒ SmartAdapters::Adapter::Delegator
constructor
Initialise SmartAdapters delegator.
-
#load ⇒ SmartAdapters::<Controller>::<Action>::<Format>Adapter
Fetch Adatapter base on request.
-
#request_params ⇒ Hash
Fetch request params.
-
#session? ⇒ Boolean
Check if it is a session request.
-
#valid_format? ⇒ Boolean
Check if the request has a valid format.
-
#valid_params? ⇒ Boolean
Check if the request has a valid params.
Constructor Details
#initialize(manager, request) ⇒ SmartAdapters::Adapter::Delegator
Initialise SmartAdapters delegator
12 13 14 15 |
# File 'lib/smart_adapters/delegator.rb', line 12 def initialize(manager, request) @manager = manager @request = request end |
Instance Attribute Details
#manager ⇒ string
Return the controller requested.
39 40 41 |
# File 'lib/smart_adapters/delegator.rb', line 39 def manager request_manager end |
Instance Method Details
#action ⇒ string
Return the action requested by the manager.
33 34 35 |
# File 'lib/smart_adapters/delegator.rb', line 33 def action request_manager.action_name end |
#api? ⇒ Boolean
Check if it is an API request
59 60 61 |
# File 'lib/smart_adapters/delegator.rb', line 59 def api? json? end |
#load ⇒ SmartAdapters::<Controller>::<Action>::<Format>Adapter
Fetch Adatapter base on request
21 22 23 24 25 26 27 28 29 |
# File 'lib/smart_adapters/delegator.rb', line 21 def load unless valid_params? raise SmartAdapters::Exceptions::InvalidRequestParamsException end unless valid_format? raise SmartAdapters::Exceptions::InvalidRequestFormatException end adapter_finder.new(request_manager) end |
#request_params ⇒ Hash
Fetch request params
77 78 79 |
# File 'lib/smart_adapters/delegator.rb', line 77 def request_params @params ||= @request.params end |
#session? ⇒ Boolean
Check if it is a session request
65 66 67 |
# File 'lib/smart_adapters/delegator.rb', line 65 def session? html? end |
#valid_format? ⇒ Boolean
Check if the request has a valid format.
53 54 55 |
# File 'lib/smart_adapters/delegator.rb', line 53 def valid_format? FORMATS.map { |format| send("#{format}?") }.any? end |
#valid_params? ⇒ Boolean
Check if the request has a valid params.
71 72 73 |
# File 'lib/smart_adapters/delegator.rb', line 71 def valid_params? request_params.present? end |