Class: JSON::SchemaBuilder::Entity
- Inherits:
-
Object
- Object
- JSON::SchemaBuilder::Entity
- Includes:
- Attribute, DSL, Validation
- Defined in:
- lib/json/schema_builder/entity.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#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
- #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=(*values) ⇒ Object
- #respond_to?(method_name, include_all = false) ⇒ Boolean
- #schema ⇒ Object
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.
28 29 30 31 32 33 34 35 |
# File 'lib/json/schema_builder/entity.rb', line 28 def initialize(name, opts = { }, &block) @name = name @children = [] self.type = self.class.registered_type initialize_parent_with opts initialize_with opts eval_block &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/json/schema_builder/entity.rb', line 64 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.
13 14 15 |
# File 'lib/json/schema_builder/entity.rb', line 13 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/json/schema_builder/entity.rb', line 13 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/json/schema_builder/entity.rb', line 13 def end |
#parent ⇒ Object
Returns the value of attribute parent.
13 14 15 |
# File 'lib/json/schema_builder/entity.rb', line 13 def parent @parent end |
Instance Method Details
#as_json ⇒ Object
52 53 54 |
# File 'lib/json/schema_builder/entity.rb', line 52 def as_json schema.to_h.as_json end |
#merge_children! ⇒ Object
46 47 48 49 50 |
# File 'lib/json/schema_builder/entity.rb', line 46 def merge_children! children.each do |child| schema.merge! child.schema end end |
#required=(*values) ⇒ Object
41 42 43 44 |
# File 'lib/json/schema_builder/entity.rb', line 41 def required=(*values) @parent.required ||= [] @parent.required << @name end |
#respond_to?(method_name, include_all = false) ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/json/schema_builder/entity.rb', line 56 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
37 38 39 |
# File 'lib/json/schema_builder/entity.rb', line 37 def schema @schema ||= Schema.new end |