Class: Alchemy::Configuration::ConfigurationOption

Inherits:
BaseOption
  • Object
show all
Defined in:
lib/alchemy/configuration/configuration_option.rb

Instance Attribute Summary collapse

Attributes inherited from BaseOption

#name, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseOption

#==, #hash, #raw_value

Constructor Details

#initialize(value:, name:, config_class:, **args) ⇒ ConfigurationOption

Returns a new instance of ConfigurationOption.



14
15
16
17
18
19
20
21
22
23
# File 'lib/alchemy/configuration/configuration_option.rb', line 14

def initialize(value:, name:, config_class:, **args)
  @name = name
  @config_class = config_class
  validate(value)
  @value = if value.is_a?(config_class)
    value
  else
    config_class.new(value)
  end
end

Instance Attribute Details

#config_classObject (readonly)

Returns the value of attribute config_class.



12
13
14
# File 'lib/alchemy/configuration/configuration_option.rb', line 12

def config_class
  @config_class
end

Class Method Details

.value_classObject



8
9
10
# File 'lib/alchemy/configuration/configuration_option.rb', line 8

def self.value_class
  Hash
end

Instance Method Details

#allowed_classesObject



30
31
32
# File 'lib/alchemy/configuration/configuration_option.rb', line 30

def allowed_classes
  super + [config_class]
end

#validate(value) ⇒ Object



25
26
27
28
# File 'lib/alchemy/configuration/configuration_option.rb', line 25

def validate(value)
  return true if value.is_a?(config_class)
  super
end