27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/changey/dsl.rb', line 27
def when_attribute(attribute_name, options = {}, &block)
if changey_tracks.empty?
include InstanceMethods
end
unless options.key?(:changes_from) || options.key?(:changes_to)
raise MissingChangeValue, "Attribute #{attribute_name} must specify a 'changes_to' or a 'changes_from' value"
end
unless block_given?
raise MissingBlock, "Attribute #{attribute_name} must specify a block"
end
track = Track.new(attribute_name)
track.direction = options.key?(:changes_from) ? :from : :to
track.expected_value = options.key?(:changes_from) ? options[:changes_from] : options[:changes_to]
if options.key?(:to) || options.key?(:from)
track.expected_other_value = options.key?(:to) ? options[:to] : options[:from]
end
BlockDSL.new(track).instance_eval(&block)
changey_tracks << track
track
end
|