Module: Skr::Concerns::StateMachine::ClassMethods
- Defined in:
- lib/skr/concerns/state_machine.rb
Instance Method Summary collapse
-
#state_machine(options = {}, &block) ⇒ Object
Mark class as a StateMachine https://github.com/aasm/aasm.
Instance Method Details
#state_machine(options = {}, &block) ⇒ Object
Mark class as a StateMachine https://github.com/aasm/aasm
Specifically it:
* Adds the methods in {InstanceMethods} to the class
* Blacklists the "state" field so it cannot be set via the API
* Allows access to the "state_event" pseudo field from the API
* Sets up the aasm library with the contents of &block
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/skr/concerns/state_machine.rb', line 23 def state_machine(={}, &block ) include InstanceMethods include AASM attr_accessor :state_event whitelist_attributes :state_event ={ no_direct_assignment: true, column: 'state', enum: true } aasm(.merge(), &block) whitelist_attributes :state_event export_methods :valid_state_events, :optional=>false blacklist_attributes :state before_save :fire_state_machine_event_on_save end |