Class: Zodra::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/zodra/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contractObject (readonly)

Returns the value of attribute contract.



5
6
7
# File 'lib/zodra/action.rb', line 5

def contract
  @contract
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/zodra/action.rb', line 5

def errors
  @errors
end

#http_methodObject

Returns the value of attribute http_method.



7
8
9
# File 'lib/zodra/action.rb', line 7

def http_method
  @http_method
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/zodra/action.rb', line 5

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/zodra/action.rb', line 5

def params
  @params
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/zodra/action.rb', line 7

def path
  @path
end

#response_definitionObject (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_typeObject

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

Returns:

  • (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_schemaObject



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