module Changey::DSL::ClassMethods
Public Instance Methods
changey_tracks()
click to toggle source
# File lib/changey/dsl.rb, line 19 def changey_tracks @changey_tracks ||= [] end
reset_changey!()
click to toggle source
# File lib/changey/dsl.rb, line 23 def reset_changey! @changey_tracks = nil end
when_attribute(attribute_name, options = {}, &block)
click to toggle source
# 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