Class: Alchemy::Configuration::BaseOption

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, name:, **args) ⇒ BaseOption

Returns a new instance of BaseOption.



10
11
12
13
14
# File 'lib/alchemy/configuration/base_option.rb', line 10

def initialize(value:, name:, **args)
  @name = name
  validate(value) unless value.nil?
  @value = value
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/alchemy/configuration/base_option.rb', line 15

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



15
16
17
# File 'lib/alchemy/configuration/base_option.rb', line 15

def value
  @value
end

Class Method Details

.value_classObject

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/alchemy/configuration/base_option.rb', line 6

def self.value_class
  raise NotImplementedError
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



27
28
29
# File 'lib/alchemy/configuration/base_option.rb', line 27

def ==(other)
  self.class == other.class && raw_value == other.raw_value
end

#allowed_classesObject



21
22
23
# File 'lib/alchemy/configuration/base_option.rb', line 21

def allowed_classes
  [self.class.value_class]
end

#hashObject



32
33
34
# File 'lib/alchemy/configuration/base_option.rb', line 32

def hash
  [self.class, raw_value].hash
end

#raw_valueObject



25
# File 'lib/alchemy/configuration/base_option.rb', line 25

def raw_value = @value

#validate(value) ⇒ Object

Raises:



17
18
19
# File 'lib/alchemy/configuration/base_option.rb', line 17

def validate(value)
  raise ConfigurationError.new(name, value, allowed_classes) unless allowed_classes.any? { value.is_a?(_1) }
end