Module: JsonWorld::DSL::ClassMethods
- Defined in:
- lib/json_world/dsl.rb
Instance Attribute Summary collapse
- #link_definitions ⇒ Array<JsonWorld::LinkDefinition>
- #property_definitions ⇒ Array<JsonWorld::PropertyDefinition>
Instance Method Summary collapse
- #as_json_schema ⇒ Hash
- #as_json_schema_without_links ⇒ Hash
- #inherited(child) ⇒ Object
- #link(link_name, options = {}) ⇒ Object
- #property(property_name, options = {}) ⇒ Object
- #property_names ⇒ Array<Symbol>
- #required_property_names ⇒ Array<Symbol>
- #to_json_schema ⇒ String
Instance Attribute Details
#link_definitions ⇒ Array<JsonWorld::LinkDefinition>
63 64 65 |
# File 'lib/json_world/dsl.rb', line 63 def link_definitions @link_definitions ||= [] end |
#property_definitions ⇒ Array<JsonWorld::PropertyDefinition>
79 80 81 |
# File 'lib/json_world/dsl.rb', line 79 def property_definitions @property_definitions ||= [] end |
Instance Method Details
#as_json_schema ⇒ Hash
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/json_world/dsl.rb', line 24 def as_json_schema { '$schema': schema, description: description, links: links_as_json_schema, properties: properties_as_json_schema, required: required_property_names, title: title, }.reject do |_key, value| value.nil? || value.empty? end end |
#as_json_schema_without_links ⇒ Hash
38 39 40 41 42 |
# File 'lib/json_world/dsl.rb', line 38 def as_json_schema_without_links as_json_schema.reject do |key, _value| key == :links end end |
#inherited(child) ⇒ Object
Note:
Override
45 46 47 48 49 |
# File 'lib/json_world/dsl.rb', line 45 def inherited(child) super child.link_definitions = link_definitions.clone child.property_definitions = property_definitions.clone end |
#link(link_name, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/json_world/dsl.rb', line 53 def link(link_name, = {}) link_definitions << JsonWorld::LinkDefinition.new( .merge( parent: self, link_name: link_name, ), ) end |
#property(property_name, options = {}) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/json_world/dsl.rb', line 69 def property(property_name, = {}) property_definitions << JsonWorld::PropertyDefinition.new( .merge( parent: self, property_name: property_name, ) ) end |
#property_names ⇒ Array<Symbol>
84 85 86 |
# File 'lib/json_world/dsl.rb', line 84 def property_names property_definitions.map(&:property_name) end |
#required_property_names ⇒ Array<Symbol>
89 90 91 |
# File 'lib/json_world/dsl.rb', line 89 def required_property_names property_definitions.reject(&:optional?).map(&:property_name) end |
#to_json_schema ⇒ String
Note:
.as_json_schema wrapper
95 96 97 |
# File 'lib/json_world/dsl.rb', line 95 def to_json_schema JSON.pretty_generate(as_json_schema) end |