Class: StructuredStore::RefResolvers::Base

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

Overview

This is the base class for all JSON Schema $ref resolvers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_schema, parent_schema, property_name, ref_string = '', context = {}) ⇒ Base

Initialize method for the base reference resolver

Parameters:

  • property_schema (Hash)

    The property’s JSON schema (with type, $ref, etc.)

  • parent_schema (SchemaInspector)

    Parent schema for definition lookups

  • property_name (String)

    Name of the property (for error messages)

  • ref_string (String) (defaults to: '')

    The $ref string if present

  • context (Hash) (defaults to: {})

    Additional context



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

def initialize(property_schema, parent_schema, property_name, ref_string = '', context = {})
  @property_schema = property_schema
  @parent_schema = parent_schema
  @property_name = property_name
  @ref_string = ref_string
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/structured_store/ref_resolvers/base.rb', line 7

def context
  @context
end

#parent_schemaObject (readonly)

Returns the value of attribute parent_schema.



7
8
9
# File 'lib/structured_store/ref_resolvers/base.rb', line 7

def parent_schema
  @parent_schema
end

#property_nameObject (readonly)

Returns the value of attribute property_name.



7
8
9
# File 'lib/structured_store/ref_resolvers/base.rb', line 7

def property_name
  @property_name
end

#property_schemaObject (readonly)

Returns the value of attribute property_schema.



7
8
9
# File 'lib/structured_store/ref_resolvers/base.rb', line 7

def property_schema
  @property_schema
end

#ref_stringObject (readonly)

Returns the value of attribute ref_string.



7
8
9
# File 'lib/structured_store/ref_resolvers/base.rb', line 7

def ref_string
  @ref_string
end

Class Method Details

.matching_ref_patternObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/structured_store/ref_resolvers/base.rb', line 14

def matching_ref_pattern
  raise NotImplementedError, 'Subclasses must implement the matching_ref_pattern method'
end

.registerObject



18
19
20
# File 'lib/structured_store/ref_resolvers/base.rb', line 18

def register
  StructuredStore::RefResolvers::Registry.register(self)
end

.unregisterObject



22
23
24
# File 'lib/structured_store/ref_resolvers/base.rb', line 22

def unregister
  StructuredStore::RefResolvers::Registry.unregister(self)
end

Instance Method Details

#define_attributeProc

This method is abstract.

Subclasses must implement this method

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

Returns:

  • (Proc)

    a lambda that defines the attribute on the singleton class

Raises:

  • (NotImplementedError)

    if the method is not implemented in a subclass



47
48
49
# File 'lib/structured_store/ref_resolvers/base.rb', line 47

def define_attribute
  raise NotImplementedError, 'Subclasses must implement the define_attribute method'
end

#options_arrayArray<Array>

This method is abstract.

Subclasses must implement this method

Returns a two dimensional array of HTML select box options

This method must be implemented by subclasses to provide specific options for reference resolution.

Returns:

  • (Array<Array>)

    Array of arrays containing id, value option pairs

Raises:

  • (NotImplementedError)

    if the method is not implemented by a subclass



59
60
61
# File 'lib/structured_store/ref_resolvers/base.rb', line 59

def options_array
  raise NotImplementedError, 'Subclasses must implement the options_array method'
end