state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Store state in a file? #64

Closed logicminds closed 6 years ago

logicminds commented 6 years ago

I want to use this in a CLI workflow based App. I don't have any need for a database so I was hoping I can store the state in a file. Does this gem allow me to store the state in a file?

And how would I do so?

seuros commented 6 years ago

Maybe have the getter and setter of the state field read/write to the file .

logicminds commented 6 years ago

getter and setter of what exactly. Can you provide an example? Should I be setting @state in the init method?

rafaelfranca commented 6 years ago

Get and setter of the state.

class Foo
  state_machine :state do
     #...
  end

  def state
    File.read(some_path)
  end

  def state=(new_state)
    File.write(some_path, new_state)
  end
end