Module: DefaultValueForPlugin::ClassMethods
- Defined in:
- lib/default_value_for.rb
Instance Method Summary collapse
Instance Method Details
#default_value_for(attribute, value = nil, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/default_value_for.rb', line 29 def default_value_for(attribute, value = nil, &block) if !method_defined?(:initialize_with_defaults) include(InstanceMethods) alias_method_chain :initialize, :defaults class_inheritable_accessor :_default_attribute_values self._default_attribute_values = ActiveSupport::OrderedHash.new end if block_given? container = BlockValueContainer.new(block) else container = NormalValueContainer.new(value) end _default_attribute_values[attribute.to_s] = container end |
#default_values(values) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/default_value_for.rb', line 44 def default_values(values) values.each_pair do |key, value| if value.kind_of? Proc default_value_for(key, &value) else default_value_for(key, value) end end end |