36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/statesman/adapters/configure_cached_current_state.rb', line 36
def configure_cached_current_state(column: :cached_current_state, touch_updated_at: false)
unless respond_to?(:transition_class) && transition_class
raise ArgumentError,
"transition_class: must be configured via configure_state_machine " \
"before calling configure_cached_current_state"
end
initial = initial_state
define_singleton_method(:cached_state_column_name) { column }
define_singleton_method(:cached_current_state_touch_updated_at?) { touch_updated_at }
before_create do
next unless respond_to?(:"#{column}=")
next unless send(column).nil?
send(:"#{column}=", initial.to_s)
end
end
|