Class: Formica::Config::Option

Inherits:
Struct
  • Object
show all
Defined in:
lib/formica.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definedObject

Returns the value of attribute defined



29
30
31
# File 'lib/formica.rb', line 29

def defined
  @defined
end

#optionObject

Returns the value of attribute option



29
30
31
# File 'lib/formica.rb', line 29

def option
  @option
end

#valueObject

Returns the value of attribute value



29
30
31
# File 'lib/formica.rb', line 29

def value
  @value
end

Instance Method Details

#validate!(value, config) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/formica.rb', line 30

def validate!(value, config)
  value = option.coerce[value] if option.coerce
  return value unless option.validate
  unless instance_exec(value, &option.validate)
    raise("invalid value #{value.inspect} for option #{option.attr_name} in #{config}")
  end
  value
end