Class: Apipie::ResponseDescription::ResponseObject

Inherits:
Object
  • Object
show all
Includes:
DSL::Base, DSL::Param
Defined in:
lib/apipie/response_description.rb

Instance Attribute Summary collapse

Attributes included from DSL::Base

#api_params, #apipie_resource_descriptions

Instance Method Summary collapse

Methods included from DSL::Param

#param, #param_group, #property, #returns

Methods included from DSL::Base

#_apipie_eval_dsl

Constructor Details

#initialize(method_description, scope, block, typename) ⇒ ResponseObject

Returns a new instance of ResponseObject.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/apipie/response_description.rb', line 11

def initialize(method_description, scope, block, typename)
  @method_description = method_description
  @scope = scope
  @param_group = {scope: scope}
  @additional_properties = false
  @typename = typename
  @headers = []

  self.instance_exec(&block) if block

  prepare_hash_params
end

Instance Attribute Details

#additional_propertiesObject

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/apipie/response_description.rb', line 8

def additional_properties
  @additional_properties
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/apipie/response_description.rb', line 9

def headers
  @headers
end

#typenameObject

Returns the value of attribute typename.



8
9
10
# File 'lib/apipie/response_description.rb', line 8

def typename
  @typename
end

Instance Method Details

#_default_param_group_scopeObject

this routine overrides Param#_default_param_group_scope and is called if Param#param_group is invoked during the instance_exec call in ResponseObject#initialize



26
27
28
# File 'lib/apipie/response_description.rb', line 26

def _default_param_group_scope
  @scope
end

#header(header_name, validator, description, options = {}) ⇒ Object

Parameters:

  • header_name (String)
  • validator (String, symbol, Class)
  • description (String)
  • options (Hash) (defaults to: {})


52
53
54
55
56
57
58
59
# File 'lib/apipie/response_description.rb', line 52

def header(header_name, validator, description, options = {})
  @headers << {
    name: header_name,
    validator: validator.to_s.downcase,
    description: description,
    options: options
  }
end

#nameObject



30
31
32
# File 'lib/apipie/response_description.rb', line 30

def name
  "response #{@code} for #{@method_description.method}"
end

#params_orderedObject



34
35
36
37
38
39
40
# File 'lib/apipie/response_description.rb', line 34

def params_ordered
  @params_ordered ||= _apipie_dsl_data[:params].map do |args|
    options = args.find { |arg| arg.is_a? Hash }
    options[:param_group] = @param_group
    Apipie::ParamDescription.from_dsl_data(@method_description, args) unless options[:only_in] == :request
  end.compact
end

#prepare_hash_paramsObject



42
43
44
45
46
# File 'lib/apipie/response_description.rb', line 42

def prepare_hash_params
  @hash_params = params_ordered.reduce({}) do |h, param|
    h.update(param.name.to_sym => param)
  end
end