Skip to content

Instantly share code, notes, and snippets.

@exAspArk
Last active February 22, 2016 22:28
Show Gist options
  • Save exAspArk/88294f3e53af202428ed to your computer and use it in GitHub Desktop.
Save exAspArk/88294f3e53af202428ed to your computer and use it in GitHub Desktop.
HACK StateMachine gem to make it work with ActiveRecord 4.2
# HACK to enable using protected methods from Rails 4.2 and initial states as default attributes for ActiveRecord
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
module ActiveRecord
public :around_save
def define_state_initializer
define_helper :instance, <<-end_eval, __FILE__, __LINE__ + 1
def initialize(*)
super do |*args|
self.class.state_machines.initialize_states(self)
yield(*args) if block_given?
end
end
end_eval
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment