Class: Formica::Option
- Inherits:
-
Struct
- Object
- Struct
- Formica::Option
- Defined in:
- lib/formica.rb
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
Returns the value of attribute attr_name.
-
#coerce ⇒ Object
Returns the value of attribute coerce.
-
#default ⇒ Object
Returns the value of attribute default.
-
#depends_on ⇒ Object
Returns the value of attribute depends_on.
-
#validate ⇒ Object
Returns the value of attribute validate.
Instance Method Summary collapse
Instance Attribute Details
#attr_name ⇒ Object
Returns the value of attribute attr_name
6 7 8 |
# File 'lib/formica.rb', line 6 def attr_name @attr_name end |
#coerce ⇒ Object
Returns the value of attribute coerce
6 7 8 |
# File 'lib/formica.rb', line 6 def coerce @coerce end |
#default ⇒ Object
Returns the value of attribute default
6 7 8 |
# File 'lib/formica.rb', line 6 def default @default end |
#depends_on ⇒ Object
Returns the value of attribute depends_on
6 7 8 |
# File 'lib/formica.rb', line 6 def depends_on @depends_on end |
#validate ⇒ Object
Returns the value of attribute validate
6 7 8 |
# File 'lib/formica.rb', line 6 def validate @validate end |
Instance Method Details
#define_on(config_class) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/formica.rb', line 7 def define_on(config_class) name = attr_name config_class.send :define_method, name do option = [name] if option.defined option.value else # evaluate all dependencies first, to help ensure we don't have to write default # blocks that clean up after themselves option.option.depends_on.each do |attr_name| public_send(attr_name) end option.defined = true default = instance_exec(&option.option.default) default = option.validate!(default, self) option.value = default end end end |