Class: FlexibleEnum::SetterMethodConfigurator
- Inherits:
-
AbstractConfigurator
- Object
- Struct
- AbstractConfigurator
- FlexibleEnum::SetterMethodConfigurator
- Defined in:
- lib/flexible_enum/setter_method_configurator.rb
Instance Attribute Summary
Attributes inherited from AbstractConfigurator
#attribute_name, #elements, #feature_module, #module_for_elements
Instance Method Summary collapse
Methods inherited from AbstractConfigurator
#add_class_method, #add_instance_method
Instance Method Details
#apply ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/flexible_enum/setter_method_configurator.rb', line 3 def apply attribute_name = self.attribute_name elements.each do |element_name, element_config| bang_method_name = element_config[:setter] || "#{element_name}!" attributes = {attribute_name => element_config[:value]} = element_config[:timestamp_attribute] || element_name add_instance_method(bang_method_name) do time = Time.now.utc attributes["#{}_on".to_sym] = time.to_date if self.class.attribute_method?("#{}_on") attributes["#{}_at".to_sym] = time if self.class.attribute_method?("#{}_at") update_attributes!(attributes) end end end |