zxyxta
Last Updated: February 25, 2016
·
460
· citizen428

Automatic named scopes with state_machine

Personally I'm not really into state_machine's approach to scopes (e.g. Vehicle.with_state :parked), so I looked for a way to turn all defined states into proper named scopes (e.g. Vehicle.parked).

state_machines[:state].states.map do |state|
  scope state.name, -> { with_status state.name }
end