Class: JsonSchemaView::Configuration::SchemaSetDictionary

Inherits:
Delegator
  • Object
show all
Defined in:
lib/json_schema_view/configuration/schema_set_dictionary.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents = nil) ⇒ SchemaSetDictionary

Returns a new instance of SchemaSetDictionary.

Parameters:

  • contents (Hash, nil) (defaults to: nil)


12
13
14
15
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 12

def initialize(contents = nil)
  @hash = ActiveSupport::HashWithIndifferentAccess.new(contents)
  super
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



9
10
11
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 9

def hash
  @hash
end

Instance Method Details

#[]=(key, value) ⇒ Object

Parameters:

  • key (#to_sym)

    The alias name of SchemaSet

  • value (String, Symbol)

    The name of SchemaSet class

Raises:

  • (TypeError)


30
31
32
33
34
35
36
37
38
39
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 30

def []=(key, value)
  raise TypeError, "key (#{key}) cannot be converted to a symbol" unless key.respond_to?(:to_sym)

  if !value.is_a?(String) && !value.is_a?(Symbol)
    raise TypeError,
          "value (#{value}) must be the name of SchemaSet class"
  end

  hash[key.to_sym] = value.to_sym
end

#HashWithIndifferentAccess{Symbol => Symbol}

Returns:

  • (HashWithIndifferentAccess{Symbol => Symbol})


19
20
21
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 19

def __getobj__
  hash
end

#Object



24
25
26
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 24

def __setobj__(_)
  # noop
end

#fetch_instance(key) ⇒ SchemaSet

Returns:

Raises:

  • (TypeError)


42
43
44
45
46
47
48
# File 'lib/json_schema_view/configuration/schema_set_dictionary.rb', line 42

def fetch_instance(key)
  klass = fetch(key).constantize

  raise TypeError, "#{klass} is not the name of SchemaSet class" unless klass < JsonSchemaView::SchemaSet

  klass.new
end