Last active
February 22, 2016 22:28
-
-
Save exAspArk/88294f3e53af202428ed to your computer and use it in GitHub Desktop.
HACK StateMachine gem to make it work with ActiveRecord 4.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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