Class: ApiMaker::IndividualCommand
- Inherits:
-
Object
- Object
- ApiMaker::IndividualCommand
- Defined in:
- lib/api_maker/individual_command.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #error(data = nil) ⇒ Object
- #fail(data = nil) ⇒ Object
-
#initialize(id:, args:, collection:, command:, primary_key: nil, response:) ⇒ IndividualCommand
constructor
A new instance of IndividualCommand.
- #model ⇒ Object
- #model_id ⇒ Object
- #result(data = nil) ⇒ Object
Constructor Details
#initialize(id:, args:, collection:, command:, primary_key: nil, response:) ⇒ IndividualCommand
Returns a new instance of IndividualCommand.
4 5 6 7 8 9 10 11 |
# File 'lib/api_maker/individual_command.rb', line 4 def initialize(id:, args:, collection:, command:, primary_key: nil, response:) @id = id @args = args @collection = collection @command = command @primary_key = primary_key @response = response end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/api_maker/individual_command.rb', line 2 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
2 3 4 |
# File 'lib/api_maker/individual_command.rb', line 2 def command @command end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/api_maker/individual_command.rb', line 2 def id @id end |
Instance Method Details
#error(data = nil) ⇒ Object
13 14 15 |
# File 'lib/api_maker/individual_command.rb', line 13 def error(data = nil) @response.error_for_command(@id, data) end |
#fail(data = nil) ⇒ Object
17 18 19 |
# File 'lib/api_maker/individual_command.rb', line 17 def fail(data = nil) @response.fail_for_command(@id, data) end |
#model ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/api_maker/individual_command.rb', line 21 def model raise "Collection wasn't set" unless @collection @model ||= @collection.find { |model| model.id.to_s == @primary_key.to_s } raise "Couldn't find model by that ID: #{@primary_key}" unless @model @model end |
#model_id ⇒ Object
30 31 32 |
# File 'lib/api_maker/individual_command.rb', line 30 def model_id @primary_key end |
#result(data = nil) ⇒ Object
34 35 36 |
# File 'lib/api_maker/individual_command.rb', line 34 def result(data = nil) @response.result_for_command(@id, ApiMaker::ResultParser.parse(data, controller: @response.controller)) end |