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>
62 63 64 |
# File 'lib/json_world/dsl.rb', line 62 def link_definitions @link_definitions ||= [] end |
#property_definitions ⇒ Array<JsonWorld::PropertyDefinition>
78 79 80 |
# File 'lib/json_world/dsl.rb', line 78 def property_definitions @property_definitions ||= [] end |
Instance Method Details
#as_json_schema ⇒ Hash
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/json_world/dsl.rb', line 24 def as_json_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
37 38 39 40 41 |
# File 'lib/json_world/dsl.rb', line 37 def as_json_schema_without_links as_json_schema.reject do |key, _value| key == :links end end |
#inherited(child) ⇒ Object
Note:
Override
44 45 46 47 48 |
# File 'lib/json_world/dsl.rb', line 44 def inherited(child) super child.link_definitions = link_definitions.clone child.property_definitions = property_definitions.clone end |
#link(link_name, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/json_world/dsl.rb', line 52 def link(link_name, = {}) link_definitions << JsonWorld::LinkDefinition.new( .merge( parent: self, link_name: link_name, ), ) end |
#property(property_name, options = {}) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/json_world/dsl.rb', line 68 def property(property_name, = {}) property_definitions << JsonWorld::PropertyDefinition.new( .merge( parent: self, property_name: property_name, ) ) end |
#property_names ⇒ Array<Symbol>
83 84 85 |
# File 'lib/json_world/dsl.rb', line 83 def property_names property_definitions.map(&:property_name) end |
#required_property_names ⇒ Array<Symbol>
88 89 90 |
# File 'lib/json_world/dsl.rb', line 88 def required_property_names property_definitions.reject(&:optional?).map(&:property_name) end |
#to_json_schema ⇒ String
Note:
.as_json_schema wrapper
94 95 96 |
# File 'lib/json_world/dsl.rb', line 94 def to_json_schema JSON.pretty_generate(as_json_schema) end |