alexpeachey / end_state

A State Machine implementation
MIT License
9 stars 5 forks source link

Proposal: Support non-delegate version #29

Closed charlierudolph closed 8 years ago

charlierudolph commented 9 years ago

I think it would be nice if you could use this without being a delegate.

object = MyMachine.decorate(object)
machine = MyMachine.new(object)

The decorator works as a delegator adding the machines methods (through method missing). And the initializer simply returns the machine.

alexpeachey commented 9 years ago

What would be the benefit of not delegating?

charlierudolph commented 8 years ago

Allows you to use a standalone state machine. I would imagine it making testing simpler and would allow it to be used in more places. I'll close if you don't agree.

alexpeachey commented 8 years ago

So all the machine needs to function is an object that has an attribute state (changable using the state_attribute macro).

So if you just wanted a "standalone state machine" then just hand it something that it wants:

machine = MyMachine.new(OpenStruct.new(state: :idle))

Then you can use the machine all you want.

Or am I missing something else about this issue?

charlierudolph commented 8 years ago

Closing as the guard / actions / concluders all get passed the delegated object so this wouldn't make sense.