geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Added a default scope of `without_<state_name>_state` #143

Closed asanger closed 9 years ago

asanger commented 9 years ago

Sometimes it's nice to just fetch everything that's not in a certain state. This will allow me to clear quite a few self-defined scopes in my projects.

geekq commented 9 years ago

A symmetric API totally makes sense for me. Thanks for your contribution!

asanger commented 9 years ago

@geekq on this same line of thought, how do you feel about scopes using the can_<event_name> syntax?

For example, if I wanted all articles that can be published, I could do Article.can_publish, which would be a scope of .where(:state_column_name => ['draft', 'hold']), with the array containing all the statuses that are allowed to transition into that new state.

Just want to get your feedback real quick before I spend the time to add it.

geekq commented 9 years ago

Thanks for the ideas! That API could be helpful in some scenarios.

However I would like to avoid integrating all the APIs, that just possibly useful. Trying to limit to some sort of core API, which is needed by most/many people.

You can extract your implementation as

asanger commented 9 years ago

Perfect - thanks for the response.