Class: Lurker::Json::Attribute

Inherits:
Schema
  • Object
show all
Defined in:
lib/lurker/json/schema/attribute.rb

Constant Summary collapse

URI =
'uri'.freeze
COLOR =
'color'.freeze
FORMAT =
'format'.freeze
DATE_TIME =
'date-time'.freeze
TYPE_MAP =
{
  'Time' => Json::STRING,
  'Hash' => Json::OBJECT,
  'Float' => Json::NUMBER,
  'Fixnum' => Json::INTEGER,
  'NilClass' => Json::NULL,
  'TrueClass' => Json::BOOLEAN,
  'FalseClass' => Json::BOOLEAN,
  'ActionDispatch::Http::UploadedFile' => Json::STRING
}.freeze

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

#eql?(schema) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/lurker/json/schema/attribute.rb', line 41

def eql?(schema)
  @schema[Json::TYPE] == attributify(schema)[Json::TYPE]
end

#merge!(schema) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lurker/json/schema/attribute.rb', line 22

def merge!(schema)
  return replace!(schema) if @schema[Json::TYPE].blank?

  schema = attributify(schema)
  return if eql?(schema)

  replace_options = {root_schema: root_schema, parent_schema: parent_schema,
                     parent_property: parent_property}

  attributes_tuple = Lurker::Json::Tuple::AnyOf.new(
    [to_hash, schema], replace_options)

  parent_schema.replace!(parent_property, attributes_tuple)
end

#replace!(schema) ⇒ Object



37
38
39
# File 'lib/lurker/json/schema/attribute.rb', line 37

def replace!(schema)
  @schema.clear.merge!(attributify schema)
end