12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/object_state/owner.rb', line 12
def object_state(options = {}, &block)
cls = self
class_name = options.fetch(:class_name, nil)
@object_state_class ||= class_name ? class_name.constantize : Class.new(ObjectState::State)
@object_state_class.class_eval do
setup_attributes cls, &block
end
if instance_methods.include?(:cache_key) && options.fetch(:merge_cache_key, true)
define_method :cache_key do |*args|
return super(*args) unless object_state
[super(*args), object_state.cache_key].reject(&:blank?).join('/')
end
end
end
|