Module: DefaultValueForPlugin::ClassMethods

Defined in:
lib/vex/active_record/plugins/default_value_for/init.rb

Instance Method Summary collapse

Instance Method Details

#default_value_for(attribute, value = nil, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vex/active_record/plugins/default_value_for/init.rb', line 43

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



58
59
60
61
62
63
64
65
66
# File 'lib/vex/active_record/plugins/default_value_for/init.rb', line 58

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