module JsonWorld::DSL::ClassMethods
Attributes
link_definitions[W]
property_definitions[W]
Public Instance Methods
as_json_schema()
click to toggle source
@return [Hash]
# 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()
click to toggle source
@return [Hash]
# 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)
click to toggle source
@note Override
Calls superclass method
# 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 = {})
click to toggle source
@param [Symbol] link_name @param [Hash{Symbol => Object}] options
# File lib/json_world/dsl.rb, line 53 def link(link_name, options = {}) link_definitions << JsonWorld::LinkDefinition.new( options.merge( parent: self, link_name: link_name, ), ) end
link_definitions()
click to toggle source
@return [Array<JsonWorld::LinkDefinition>]
# File lib/json_world/dsl.rb, line 63 def link_definitions @link_definitions ||= [] end
property(property_name, options = {})
click to toggle source
@param [Symbol] property_name @param [Hash{Symbol => Object}] options
# File lib/json_world/dsl.rb, line 69 def property(property_name, options = {}) property_definitions << JsonWorld::PropertyDefinition.new( options.merge( parent: self, property_name: property_name, ) ) end
property_definitions()
click to toggle source
@return [Array<JsonWorld::PropertyDefinition>]
# File lib/json_world/dsl.rb, line 79 def property_definitions @property_definitions ||= [] end
property_names()
click to toggle source
@return [Array<Symbol>]
# File lib/json_world/dsl.rb, line 84 def property_names property_definitions.map(&:property_name) end
required_property_names()
click to toggle source
@return [Array<Symbol>]
# File lib/json_world/dsl.rb, line 89 def required_property_names property_definitions.reject(&:optional?).map(&:property_name) end
to_json_schema()
click to toggle source
@note .as_json_schema wrapper @return [String]
# File lib/json_world/dsl.rb, line 95 def to_json_schema JSON.pretty_generate(as_json_schema) end
Private Instance Methods
description(value = nil)
click to toggle source
@return [String, nil]
# File lib/json_world/dsl.rb, line 102 def description(value = nil) @description ||= value end
links_as_json_schema()
click to toggle source
@return [Array<Hash>]
# File lib/json_world/dsl.rb, line 107 def links_as_json_schema link_definitions.map(&:as_json_schema) end
properties_as_json_schema()
click to toggle source
@return [Hash]
# File lib/json_world/dsl.rb, line 112 def properties_as_json_schema property_definitions.inject({}) do |result, property_definition| result.merge( property_definition.property_name => property_definition.as_json_schema, ) end end
schema(value = nil)
click to toggle source
@return [String, nil]
# File lib/json_world/dsl.rb, line 126 def schema(value = nil) @schema ||= value end
title(value = nil)
click to toggle source
@return [String, nil]
# File lib/json_world/dsl.rb, line 121 def title(value = nil) @title ||= value end