svenfuchs / simple_states Goto Github PK
View Code? Open in Web Editor NEWA super-slim statemachine-like support library
License: MIT License
A super-slim statemachine-like support library
License: MIT License
Using methods like item.confirm!, item.deny! improve readability.
You understand that this method changes internals of the given entity, and it's more obvious in general, too.
Do you think it's something you would like to see?
Thanks!
Hi,
I was thinking of adding reset and reset! methods that would reset model to it's initial state, and maybe calling some reset callback.
Do you think it could be any useful?
# Running:
..../skipped/.bundle/gems/gems/simple_states-2.0.0/lib/simple_states/event.rb:44: warning: Hash#index is deprecated; use Hash#key
/skipped/.bundle/gems/gems/simple_states-2.0.0/lib/simple_states/event.rb:44: warning: Hash#index is deprecated; use Hash#key
....
ruby 2.2.3
When i use select in active record query wich not include attribute state, instantiate record model raise exception
Project.select(:id).first
Project Load (0.1ms) SELECT "projects"."id" FROM "projects" ORDER BY "projects"."id" ASC LIMIT ? [["LIMIT", 1]]
ActiveModel::MissingAttributeError: missing attribute: state
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute_methods/read.rb:78:in `block in _read_attribute'
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute_set.rb:42:in `block in fetch_value'
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute.rb:194:in `value'
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute_set.rb:42:in `fetch_value'
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute_methods/read.rb:78:in `_read_attribute'
from /home/damir/project/.bundle/gems/gems/activerecord-5.0.0.beta1/lib/active_record/attribute_methods/read.rb:48:in `__temp__3747164756'
from /home/damir/project/.bundle/gems/gems/simple_states-2.0.0/lib/simple_states.rb:47:in `state'
from /home/damiconst.after_initialize(:init_state)r/project/.bundle/gems/gems/simple_states-2.0.0/lib/simple_states.rb:39:in `init_stat
dig in to code problem in callback after_initialize(:init_state)
def init_state
singleton_class.send(:include, self.class::States) unless self.class.respond_to?(:prepend)
self.state = self.class.initial_state if self.state.nil?
end
def state
state = super
state.to_sym if state
end
self.state.nil?
does not check that the attributes contain state
In the event of :finish
, how do you decide between target states :passed
and :failed
in the README example?
The gem is awesome but comes with a small issue: In the Readme, there's a part where you say you'll see the ActiveRecord integration later, but that later never comes.
If you please add an integration example would be great.
Thanks in advance!
Please correct me if I am wrong, but at the moment it is not possible to define multiple events with the same name. It would be good if you were allowed to do this, as long as there were not multiple events with the same name stemming from the same state. Ie. I would like to define:
event :close, from: :created, to: :closed
event :close, from: :open, to: :closed
But am having to define
event :close_created, from: :created, to: :closed
event :close_open, from: :open, to: :closed
This could be implemented by defining event method names by concatenating their name and starting state. Would you accept a PR with this proposed method, or do you have any other opinions?
Thanks
Jack
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.