Class: JSON::Generator::ObjectAttribute

Inherits:
BasicAttribute show all
Defined in:
lib/json/generator/object_attribute.rb

Instance Method Summary collapse

Methods inherited from BasicAttribute

#initialize, #required?

Constructor Details

This class inherits a constructor from JSON::Generator::BasicAttribute

Instance Method Details

#generateObject



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/json/generator/object_attribute.rb', line 4

def generate
  return nil unless required?
  return {} unless @attributes.has_key?('properties')

  @attributes['properties'].inject({}) do |json, (property_name, property_attributes)|
    attribute = AttributeFactory.create(property_attributes)
    if attribute.required?
      json[property_name] = attribute.generate
    end
    json
  end
end