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
- #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>
55 56 57 |
# File 'lib/json_world/dsl.rb', line 55 def link_definitions @link_definitions ||= [] end |
#property_definitions ⇒ Array<JsonWorld::PropertyDefinition>
71 72 73 |
# File 'lib/json_world/dsl.rb', line 71 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 |
#inherited(child) ⇒ Object
Note:
Override
37 38 39 40 41 |
# File 'lib/json_world/dsl.rb', line 37 def inherited(child) super child.link_definitions = link_definitions child.property_definitions = property_definitions.clone end |
#link(link_name, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/json_world/dsl.rb', line 45 def link(link_name, = {}) link_definitions << JsonWorld::LinkDefinition.new( .merge( parent: self, link_name: link_name, ), ) end |
#property(property_name, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/json_world/dsl.rb', line 61 def property(property_name, = {}) property_definitions << JsonWorld::PropertyDefinition.new( .merge( parent: self, property_name: property_name, ) ) end |
#property_names ⇒ Array<Symbol>
76 77 78 |
# File 'lib/json_world/dsl.rb', line 76 def property_names property_definitions.map(&:property_name) end |
#required_property_names ⇒ Array<Symbol>
81 82 83 |
# File 'lib/json_world/dsl.rb', line 81 def required_property_names property_definitions.reject(&:optional?).map(&:property_name) end |
#to_json_schema ⇒ String
Note:
.as_json_schema wrappter
87 88 89 |
# File 'lib/json_world/dsl.rb', line 87 def to_json_schema JSON.pretty_generate(as_json_schema) end |