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.



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

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

Instance Attribute Details

#additional_propertiesObject

Returns the value of attribute additional_properties.



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

def additional_properties
  @additional_properties
end

#typenameObject

Returns the value of attribute typename.



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

def typename
  @typename
end

Class Method Details

.from_self_describing_class(cls) ⇒ Object



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

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



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

def add(prop_desc)
  if prop_desc.is_a? PropDesc
    @property_descs << prop_desc
  elsif prop_desc.is_a? Modifier
    prop_desc.apply(self)
  else
    raise "Unrecognized prop_desc type (#{prop_desc.class})"
  end
end

#add_property_descriptions(prop_descs) ⇒ Object



182
183
184
185
186
# File 'lib/apipie/response_description_adapter.rb', line 182

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

#allow_additional_propertiesObject



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

def allow_additional_properties
  additional_properties
end

#is_array?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/apipie/response_description_adapter.rb', line 196

def is_array?
  false
end

#params_orderedObject



192
193
194
# File 'lib/apipie/response_description_adapter.rb', line 192

def params_ordered
  @property_descs
end

#property(name, expected_type, options) ⇒ Object



188
189
190
# File 'lib/apipie/response_description_adapter.rb', line 188

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

#to_jsonObject



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

def to_json
  params_ordered.to_json
end