Class: Vigia::Adapters::Blueprint

Inherits:
Vigia::Adapter show all
Defined in:
lib/vigia/adapters/blueprint.rb

Instance Attribute Summary collapse

Attributes inherited from Vigia::Adapter

#source_file, #structure

Instance Method Summary collapse

Methods inherited from Vigia::Adapter

instance, #required_payload?, setup_adapter, template, #with_payload?

Instance Attribute Details

#apibObject (readonly)

Returns the value of attribute apib.



5
6
7
# File 'lib/vigia/adapters/blueprint.rb', line 5

def apib
  @apib
end

#apib_sourceObject (readonly)

Returns the value of attribute apib_source.



5
6
7
# File 'lib/vigia/adapters/blueprint.rb', line 5

def apib_source
  @apib_source
end

Instance Method Details

#find_action(url, method) ⇒ Object



120
121
122
123
124
# File 'lib/vigia/adapters/blueprint.rb', line 120

def find_action(url, method)
  resources_by_url(url).map(&:actions).flatten.select do|action|
    action && (method.nil? || action.method.downcase == method.to_s.downcase)
  end.first
end

#headers_for(action, transactional_example, response, include_payload = true) ⇒ Object



72
73
74
75
76
# File 'lib/vigia/adapters/blueprint.rb', line 72

def headers_for(action, transactional_example, response, include_payload = true)
  headers  = headers_for_response(response)
  headers += headers_for_payload(transactional_example, response) if with_payload?(action.method) && include_payload
  compile_headers(headers)
end

#inspector(object) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/vigia/adapters/blueprint.rb', line 102

def inspector object
  case object
  when RedSnow::ResourceGroup
    locate_in_sourcemap(:resource_groups, object)
  when RedSnow::Resource
    locate_in_sourcemap(:resources, object)
  when RedSnow::Action
    locate_in_sourcemap(:actions, object)
  when RedSnow::TransactionExample
    first_response = object.responses.first
    locate_in_sourcemap(:responses, first_response)
  when RedSnow::Payload
    locate_in_sourcemap(:responses, object)
  else
    nil
  end
end

#parameters_for(resource, action) ⇒ Object



78
79
80
81
82
# File 'lib/vigia/adapters/blueprint.rb', line 78

def parameters_for(resource, action)
  (resource.parameters.collection + action.parameters.collection).each_with_object([]) do |parameter, collection|
    collection << { name: parameter.name, value: parameter.example_value, required: (parameter.use == :required) }
  end
end

#payload_for(transactional_example, response) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vigia/adapters/blueprint.rb', line 90

def payload_for(transactional_example, response)
  payload = get_payload(transactional_example, response)

  if required_payload?(transactional_example.action.method) && payload.nil?
    raise "Unable to load payload for response #{ response.name }"
  elsif payload.nil?
    nil
  else
    payload.body
  end
end

#required_parameters_for(resource, action) ⇒ Object



84
85
86
87
88
# File 'lib/vigia/adapters/blueprint.rb', line 84

def required_parameters_for(resource, action)
  parameters_for(resource, action).select do |param|
    param[:required]
  end
end