Class: TheGrid::Api
- Inherits:
-
Object
- Object
- TheGrid::Api
- Defined in:
- lib/the_grid/api.rb
Defined Under Namespace
Classes: Command
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Instance Method Summary collapse
- #compose!(params) ⇒ Object
- #delegate(commands) ⇒ Object
-
#initialize(relation) ⇒ Api
constructor
A new instance of Api.
- #run_command!(name, params) ⇒ Object
Constructor Details
#initialize(relation) ⇒ Api
Returns a new instance of Api.
5 6 7 8 |
# File 'lib/the_grid/api.rb', line 5 def initialize(relation) @relation = relation = { :delegated_commands => {} } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/the_grid/api.rb', line 3 def end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
3 4 5 |
# File 'lib/the_grid/api.rb', line 3 def relation @relation end |
Instance Method Details
#compose!(params) ⇒ Object
14 15 16 17 18 |
# File 'lib/the_grid/api.rb', line 14 def compose!(params) configure(params).fetch(:cmd).each do |cmd| @relation = run_command!(cmd, params) unless command(cmd).batch? end end |
#delegate(commands) ⇒ Object
10 11 12 |
# File 'lib/the_grid/api.rb', line 10 def delegate(commands) [:delegated_commands].merge! commands.stringify_keys end |
#run_command!(name, params) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/the_grid/api.rb', line 20 def run_command!(name, params) .merge! command(name).contextualize(@relation, params) if command_delegated?(name) assoc_name = [:delegated_commands][name.to_s] assoc = @relation.reflections[assoc_name].klass.scoped @relation.merge command(name).execute_on(assoc, params) else command(name).execute_on(@relation, params) end end |