class Apipony::Response
Attributes
attributes[RW]
example[RW]
status[RW]
Public Class Methods
new(status, array: false, &block)
click to toggle source
# File lib/apipony/response.rb, line 3 def initialize(status, array: false, &block) @status = status @attributes = [] @array = array instance_eval(&block) if block_given? end
Public Instance Methods
attribute(name, **params, &block)
click to toggle source
# File lib/apipony/response.rb, line 22 def attribute(name, **params, &block) if params[:example] @use_attribute_examples = true end @attributes << Apipony::ResponseAttribute.new(name, **params, &block) end
is_array?()
click to toggle source
# File lib/apipony/response.rb, line 10 def is_array? !! @array end
Private Instance Methods
build_example_from_attributes()
click to toggle source
# File lib/apipony/response.rb, line 36 def build_example_from_attributes build = Hash.new @attributes.each do |attr| build[attr.name] = attr.example if attr.example end @example ||= Apipony::ExampleResponse.new case @example.body when Hash @example.body.merge! build @example.body = [@example.body] if is_array? when NilClass @example.body = (is_array? ? [build] : build) end @example end
find_example()
click to toggle source
# File lib/apipony/response.rb, line 29 def find_example if @use_attribute_examples build_example_from_attributes end @example end