Class: StructuredStore::RefResolvers::BlankRefResolver

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

Overview

This class resolves properties where no $ref is defined.

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



10
11
12
# File 'lib/structured_store/ref_resolvers/blank_ref_resolver.rb', line 10

def self.matching_ref_pattern
  /\A\z/
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



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

def define_attribute
  type = property_schema['type']

  # Handle arrays
  return define_array_attribute if type == 'array'

  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’ property definition Each element contains a duplicate of the enum option for both the label and value

For arrays, delegates to a resolver for the items to get options recursively

Returns:

  • (Array<Array>)

    Array of arrays containing id, value option pairs



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/structured_store/ref_resolvers/blank_ref_resolver.rb', line 40

def options_array
  # For arrays, delegate to the items resolver
  if property_schema['type'] == 'array'
    items_resolver = create_items_resolver
    return items_resolver.options_array
  end

  # For non-arrays, get enum directly
  enum = property_schema['enum']
  enum&.map { |option| [option, option] } || []
end