Class: Apipie::ResponseDescriptionAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/response_description_adapter.rb,
lib/apipie/response_description_adapter.rb,
lib/apipie/response_description_adapter.rb

Overview

Defined Under Namespace

Classes: AdditionalPropertiesModifier, Modifier, PropDesc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(typename) ⇒ ResponseDescriptionAdapter

Returns a new instance of ResponseDescriptionAdapter.



157
158
159
160
161
# File 'lib/apipie/response_description_adapter.rb', line 157

def initialize(typename)
  @property_descs = []
  @additional_properties = false
  @typename = typename
end

Instance Attribute Details

#additional_propertiesObject

Returns the value of attribute additional_properties.



163
164
165
# File 'lib/apipie/response_description_adapter.rb', line 163

def additional_properties
  @additional_properties
end

#typenameObject

Returns the value of attribute typename.



163
164
165
# File 'lib/apipie/response_description_adapter.rb', line 163

def typename
  @typename
end

Class Method Details

.from_self_describing_class(cls) ⇒ Object



150
151
152
153
154
155
# File 'lib/apipie/response_description_adapter.rb', line 150

def self.from_self_describing_class(cls)
  adapter = ResponseDescriptionAdapter.new(cls.to_s)
  props = cls.describe_own_properties
  adapter.add_property_descriptions(props)
  adapter
end

Instance Method Details

#add(prop_desc) ⇒ Object



173
174
175
176
177
178
179
180
181
182
# File 'lib/apipie/response_description_adapter.rb', line 173

def add(prop_desc)
  case prop_desc
  when PropDesc
    @property_descs << prop_desc
  when Modifier
    prop_desc.apply(self)
  else
    raise "Unrecognized prop_desc type (#{prop_desc.class})"
  end
end

#add_property_descriptions(prop_descs) ⇒ Object



184
185
186
187
188
# File 'lib/apipie/response_description_adapter.rb', line 184

def add_property_descriptions(prop_descs)
  for prop_desc in prop_descs
    add(prop_desc)
  end
end

#allow_additional_propertiesObject



165
166
167
# File 'lib/apipie/response_description_adapter.rb', line 165

def allow_additional_properties
  additional_properties
end

#is_array?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/apipie/response_description_adapter.rb', line 198

def is_array?
  false
end

#params_orderedObject



194
195
196
# File 'lib/apipie/response_description_adapter.rb', line 194

def params_ordered
  @property_descs
end

#property(name, expected_type, options) ⇒ Object



190
191
192
# File 'lib/apipie/response_description_adapter.rb', line 190

def property(name, expected_type, options)
  @property_descs << PropDesc.new(name, expected_type, options)
end

#to_jsonObject



169
170
171
# File 'lib/apipie/response_description_adapter.rb', line 169

def to_json
  params_ordered.to_json
end