state_machines
time_for_a_boolean
state_machines | time_for_a_boolean | |
---|---|---|
5 | 3 | |
795 | 91 | |
1.0% | - | |
3.3 | 0.0 | |
11 days ago | 7 months ago | |
Ruby | Ruby | |
MIT License | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
state_machines
- Gem adds support for creating state machines for attributes on any Ruby class
-
Practical State Machinery
State Machines (Ruby) - A popular library providing a Ruby DSL for easily building finite state machines
-
Why Developers Never Use State Machines (2011)
As a regular user of the state_machine Ruby gem, I wouldn't recommend it. If you don't believe me, just check out the "Class definition" section of the usage examples: https://github.com/state-machines/state_machines#usage
The problems are obvious. It's built on magic and indirection. This leads to difficult to debug state machine problems. For anything beyond simple state machines you quickly lose any idea of what your object is doing.
-
ActiveRecord: Adding Boolean methods for DateTime columns
Might this be better handled with a state machine with active record integration?
-
Ruby 3 Released
Here's an example of how it can happen - look at the code examples in https://github.com/state-machines/state_machines - almost everything you are coding is in the DSL of that library if you are using it:
time_for_a_boolean
-
ActiveRecord: Adding Boolean methods for DateTime columns
There's a gem that handles this behavior. I haven't personally used it, but I heard about it on the Bikeshed podcast. time_for_a_boolean
-
Is there a convention to implement this (more) efficiently and elegantly?
There's a gem for treating timestamp columns like booleans https://github.com/calebhearth/time_for_a_boolean. I haven't personally used it, but it seems to be a similar solution to what some people here have suggested
-
Mechanism for marking messages "read" in our chat module in our rail's app.
It might not be the most efficient if your app scales to millions of messages, but perhaps adding another table with a schema like `message_id`, `user_id`, `read_at`. Don't forget to eager load this new relation, as it can lead to N+1 errors.On the app that I work on, we use the gem time_for_a_boolean which allows us to treat a nullable timestamp field. It might be useful for your project too.
What are some alternatives?
AASM - AASM - State machines for Ruby classes (plain Ruby, ActiveRecord, Mongoid, NoBrainer, Dynamoid)
state_machines-activerecord - StateMachines Active Record Integration
State Machine - Adds support for creating state machines for attributes on any Ruby class
rubygems - Library packaging and distribution for Ruby.
Statesman - A statesmanlike state machine library.
simple_states - A super-slim statemachine-like support library
state_shifter
transitions - State machine extracted from ActiveModel
FiniteMachine - A minimal finite state machine with a straightforward syntax.
Workflow - Ruby finite-state-machine-inspired API for modeling workflow
StatefulEnum - A very simple state machine plugin built on top of ActiveRecord::Enum
StrictMachine