class Lurker::Json::List

Public Instance Methods

merge!(schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 4
def merge!(schema)
  if schema.is_a?(Array)
    schema.each { |payload| @schema[Json::ITEMS].merge!(payload) }
  else
    @schema[Json::ITEMS].merge!(schema)
  end
end
replace!(property, schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 12
def replace!(property, schema)
  if @schema[Json::ITEMS].is_a?(Lurker::Json::Attribute)
    @schema[Json::ITEMS] = schema
  else
    @schema[Json::ITEMS].replace!(property, schema)
  end
end

Private Instance Methods

initialize_default_properties(empty_items = {}) click to toggle source
# File lib/lurker/json/schema/list.rb, line 22
def initialize_default_properties(empty_items = {})
  @schema[Json::TYPE] ||= Json::ARRAY
  @schema[Json::ITEMS] ||= polymorph_items(empty_items)
end
parse_array(schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 32
def parse_array(schema)
  initialize_default_properties([])
  return if schema.empty?

  @schema[Json::ITEMS] = @parser.typed.parse(schema.shift)
  schema.each { |payload| @schema[Json::ITEMS].merge!(payload) }
end
parse_hash(schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 40
def parse_hash(schema)
  @schema.merge!(schema)
  @schema[Json::ITEMS] = @parser.typed(polymorph_if_empty: true)
    .parse(schema.delete(Json::ITEMS) || schema)

  initialize_default_properties
end
parse_schema(schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 27
def parse_schema(schema)
  @schema = {}
  schema.is_a?(Array) ? parse_array(schema.dup) : parse_hash(schema.dup)
end
polymorph_items(schema) click to toggle source
# File lib/lurker/json/schema/list.rb, line 48
def polymorph_items(schema)
  options = subschema_options.merge!(parent_property: Json::ITEMS)
  Lurker::Json::Polymorph.new(schema, options)
end