Module: DefaultValueForPlugin::ClassMethods

Defined in:
lib/default_value_for/core.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) default_value_for(attribute, value = nil, &block)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/default_value_for/core.rb', line 47

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

- (Object) default_values(values)



62
63
64
65
66
67
68
69
70
# File 'lib/default_value_for/core.rb', line 62

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