Class: JSON::SchemaBuilder::Object

Inherits:
Entity
  • Object
show all
Defined in:
lib/json/schema_builder/object.rb

Instance Attribute Summary

Attributes inherited from Entity

#children, #error, #fragment, #fragments, #name, #options, #parent

Instance Method Summary collapse

Methods inherited from Entity

#add_fragment, #as_json, #merge_children!, #method_missing, #respond_to?, #schema

Methods included from Helpers

#id, #object_or_array

Methods included from Validation

#fully_validate, #validate, #validate!

Methods included from DSL

#entity

Constructor Details

#initialize(name, opts = { }, &block) ⇒ Object

Returns a new instance of Object.



14
15
16
17
18
19
20
# File 'lib/json/schema_builder/object.rb', line 14

def initialize(name, opts = { }, &block)
  self.properties = { }
  super
  children.each do |child|
    self.properties[child.name] = child.as_json
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JSON::SchemaBuilder::Entity

Instance Method Details

#required(*values) ⇒ Object Also known as: required=



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/json/schema_builder/object.rb', line 22

def required(*values)
  case values
  when []
    @schema[:required]
  when [true]
    @parent.required ||= []
    @parent.required << @name
  else
    @schema[:required] = values.flatten
  end
end