Class: Lurker::Json::Polymorph
- Defined in:
- lib/lurker/json/schema/polymorph.rb
Constant Summary
Constants inherited from Schema
Schema::EXTENSIONS, Schema::REQUEST_PARAMETERS, Schema::RESPONSE_CODES, Schema::RESPONSE_PARAMETERS
Instance Attribute Summary
Attributes inherited from Schema
#parent_property, #parent_schema, #root_schema, #uri
Instance Method Summary collapse
Methods inherited from Schema
#documentation, #documentation_uri, #initialize, #method_missing, #reorder!, #respond_to_missing?, #root?, #to_hash, #to_json, #to_yaml
Methods included from Concerns::Validatable
#to_validation_schema, #validate
Constructor Details
This class inherits a constructor from Lurker::Json::Schema
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Lurker::Json::Schema
Instance Method Details
#merge!(schema) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lurker/json/schema/polymorph.rb', line 4 def merge!(schema) case parent_schema when Lurker::Json::Object parent_schema[Json::PROPERTIES][parent_property] = @parser.typed.parse(schema) when Lurker::Json::List if schema.is_a?(Array) return if schema.empty? schema = schema.dup parent_schema[Json::ITEMS] = @parser.typed.parse(schema.shift) parent_schema.merge!(schema) else parent_schema[Json::ITEMS] = @parser.typed.parse(schema) end else parent_schema[parent_property] = @parser.typed.parse(schema) end end |
#replace!(property, schema) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lurker/json/schema/polymorph.rb', line 23 def replace!(property, schema) morph = Lurker::Json::Object.new({}, ) case parent_schema when Lurker::Json::Object parent_schema[Json::PROPERTIES][parent_property] = morph parent_schema.replace!(property, schema) when Lurker::Json::List parent_schema[Json::ITEMS] = morph parent_schema.replace!(property, schema) else parent_schema[parent_property] = morph parent_schema.replace!(property, schema) end end |