Class: StructuredStore::RefResolvers::DefinitionsResolver

Inherits:
Base
  • Object
show all
Defined in:
lib/structured_store/ref_resolvers/definitions_resolver.rb

Overview

This class resolves $ref strings that point to definitions within the schema.

Instance Attribute Summary

Attributes inherited from Base

#context, #parent_schema, #property_name, #property_schema, #ref_string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, register, unregister

Constructor Details

This class inherits a constructor from StructuredStore::RefResolvers::Base

Class Method Details

.matching_ref_patternObject



11
12
13
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 11

def self.matching_ref_pattern
  %r{\A#/definitions/}
end

Instance Method Details

#define_attributeProc

Defines the rails attribute(s) on the given singleton class

Returns:

  • (Proc)

    a lambda that defines the attribute on the singleton class

Raises:

  • (RuntimeError)

    if the property type is unsupported



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 19

def define_attribute
  type = local_definition['type']

  unless %w[boolean integer string].include?(type)
    raise "Unsupported attribute type: #{type.inspect} for property '#{property_name}'"
  end

  # Define the attribute on the singleton class of the object
  lambda do |object|
    object.singleton_class.attribute(property_name, type.to_sym)
  end
end

#options_arrayArray<Array>

Returns a two dimensional array of options from the ‘enum’ definition Each element contains a duplicate of the enum option for both the label and value

Returns:

  • (Array<Array>)

    Array of arrays containing id, value option pairs



36
37
38
39
40
# File 'lib/structured_store/ref_resolvers/definitions_resolver.rb', line 36

def options_array
  enum = local_definition['enum']

  enum.map { |option| [option, option] }
end