Closed bmalets closed 5 years ago
Hi Bohdan!
Thanks for using finite_machine
!
I don't believe this is anything to do with finite_machine
not working on latest Ruby. I've installed Ruby 2.6.0-preview3
and 2.6.0-rc1
and both pass the test suite. Also, please notice that finite_machine
is also tested against Ruby master branch on travis.
I'm pretty sure that you're not using the latest version v0.12.0
. Why is that? For starters, there is no more target
assignment, the context is directly provided as an argument to define
. But please bear in mind that define
provides an anonymous class now! If you look at your second example you will see that you're receiving exactly that:
=> #<Class:0x00007fd1f921aef8>
Please see define for more information. In your case you probably need to use new to create an instance of FiniteMachine
instead:
def finite_machine
@state_engine ||= FiniteMachine.new(self) do
...
Also please bear in mind that events
scope doesn't exist any more which should generate an error for you as well! You specify events directly inside the block:
initial :cart
event :create, cart: :pending
event :prepare, pending: :prepared
...
Once you update your code I'm certain it will work on the latest Ruby!
The latest finite_machine
had a lot of internals rewritten to make it much simpler, remove ambiguity and unnecessary calls and increase performance.
Does this gem support ruby
2.6.0
version?Found that
model_object.finite_machine.current
with ruby "ruby-2.6.0-preview3" returns an array of Proc instead if current state.Different behaviors:
Code example (model and concern with finite machine):