Class: Zodra::Action
- Inherits:
-
Object
- Object
- Zodra::Action
- Defined in:
- lib/zodra/action.rb
Instance Attribute Summary collapse
-
#contract ⇒ Object
readonly
Returns the value of attribute contract.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#response_definition ⇒ Object
readonly
Returns the value of attribute response_definition.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
Instance Method Summary collapse
- #add_error(code, status:) ⇒ Object
- #collection! ⇒ Object
- #collection? ⇒ Boolean
- #find_error(code) ⇒ Object
-
#initialize(name:, contract: nil) ⇒ Action
constructor
A new instance of Action.
- #response_schema ⇒ Object
Constructor Details
#initialize(name:, contract: nil) ⇒ Action
Returns a new instance of Action.
9 10 11 12 13 14 15 16 17 |
# File 'lib/zodra/action.rb', line 9 def initialize(name:, contract: nil) @name = name @contract = contract @params = Definition.new(name: :"#{name}_params", kind: :object) @response_definition = Definition.new(name: :"#{name}_response", kind: :object) @response_type = nil @collection = false @errors = {} end |
Instance Attribute Details
#contract ⇒ Object (readonly)
Returns the value of attribute contract.
5 6 7 |
# File 'lib/zodra/action.rb', line 5 def contract @contract end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/zodra/action.rb', line 5 def errors @errors end |
#http_method ⇒ Object
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/zodra/action.rb', line 7 def http_method @http_method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/zodra/action.rb', line 5 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/zodra/action.rb', line 5 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/zodra/action.rb', line 7 def path @path end |
#response_definition ⇒ Object (readonly)
Returns the value of attribute response_definition.
5 6 7 |
# File 'lib/zodra/action.rb', line 5 def response_definition @response_definition end |
#response_type ⇒ Object
Returns the value of attribute response_type.
7 8 9 |
# File 'lib/zodra/action.rb', line 7 def response_type @response_type end |
Instance Method Details
#add_error(code, status:) ⇒ Object
19 20 21 |
# File 'lib/zodra/action.rb', line 19 def add_error(code, status:) @errors[code.to_sym] = { code: code.to_sym, status: status } end |
#collection! ⇒ Object
31 32 33 |
# File 'lib/zodra/action.rb', line 31 def collection! @collection = true end |
#collection? ⇒ Boolean
27 28 29 |
# File 'lib/zodra/action.rb', line 27 def collection? @collection end |
#find_error(code) ⇒ Object
23 24 25 |
# File 'lib/zodra/action.rb', line 23 def find_error(code) @errors[code.to_sym] end |
#response_schema ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/zodra/action.rb', line 35 def response_schema if response_type contract&.resolve_type(response_type) || TypeRegistry.global.find!(response_type) else response_definition end end |