Class: JSON::SchemaBuilder::Entity
- Inherits:
-
Object
- Object
- JSON::SchemaBuilder::Entity
- Includes:
- Attribute, DSL, Helpers, Validation
- Defined in:
- lib/json/schema_builder/entity.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#error ⇒ Object
Returns the value of attribute error.
-
#fragment ⇒ Object
Returns the value of attribute fragment.
-
#fragments ⇒ Object
Returns the value of attribute fragments.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_fragment(child) ⇒ Object
- #as_json ⇒ Object
-
#initialize(name, opts = { }, &block) ⇒ Entity
constructor
A new instance of Entity.
- #merge_children! ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #required ⇒ Object
- #required=(*values) ⇒ Object
- #respond_to?(method_name, include_all = false) ⇒ Boolean
- #schema ⇒ Object
Methods included from Helpers
#empty_string, #id, #object_or_array
Methods included from Validation
#fully_validate, #validate, #validate!
Methods included from DSL
Constructor Details
#initialize(name, opts = { }, &block) ⇒ Entity
Returns a new instance of Entity.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/json/schema_builder/entity.rb', line 30 def initialize(name, opts = { }, &block) @name = name @children = [] @fragments = Hash.new { |hash, key| hash[key] = ::Array.new } @fragments["#/"] << self if opts[:root] self.type = self.class.registered_type initialize_parent_with opts initialize_with opts eval_block &block extract_types end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/json/schema_builder/entity.rb', line 78 def method_missing(method_name, *args, &block) if @parent_context && respond_to?(method_name, true) @parent_context.send method_name, *args, &block else super end end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def children @children end |
#error ⇒ Object
Returns the value of attribute error.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def error @error end |
#fragment ⇒ Object
Returns the value of attribute fragment.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def fragment @fragment end |
#fragments ⇒ Object
Returns the value of attribute fragments.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def fragments @fragments end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def end |
#parent ⇒ Object
Returns the value of attribute parent.
15 16 17 |
# File 'lib/json/schema_builder/entity.rb', line 15 def parent @parent end |
Instance Method Details
#add_fragment(child) ⇒ Object
42 43 44 45 |
# File 'lib/json/schema_builder/entity.rb', line 42 def add_fragment(child) @fragments[child.fragment] << child @parent.add_fragment(child) if @parent end |
#as_json ⇒ Object
66 67 68 |
# File 'lib/json/schema_builder/entity.rb', line 66 def as_json schema.as_json end |
#merge_children! ⇒ Object
60 61 62 63 64 |
# File 'lib/json/schema_builder/entity.rb', line 60 def merge_children! children.each do |child| schema.merge! child.schema end end |
#required ⇒ Object
51 52 53 |
# File 'lib/json/schema_builder/entity.rb', line 51 def required schema["required"] || [] end |
#required=(*values) ⇒ Object
55 56 57 58 |
# File 'lib/json/schema_builder/entity.rb', line 55 def required=(*values) @parent.schema["required"] ||= [] @parent.schema["required"] << @name end |
#respond_to?(method_name, include_all = false) ⇒ Boolean
70 71 72 73 74 75 76 |
# File 'lib/json/schema_builder/entity.rb', line 70 def respond_to?(method_name, include_all = false) if @parent_context @parent_context.respond_to? method_name, include_all else super end end |
#schema ⇒ Object
47 48 49 |
# File 'lib/json/schema_builder/entity.rb', line 47 def schema @schema ||= Schema.new({}, self) end |