Module: StrictStates

Defined in:
lib/strict_states.rb,
lib/strict_states/checker.rb,
lib/strict_states/version.rb,
lib/strict_states/strict_hash.rb

Overview

The STRICT paradigm:

* Will raise an error if states are spelled wrong when lookups happen through this paradigm.
* Typos will be noisy, and many of them will error at app-load, so impossible to miss.

Uses the StrictHash to accomplish this. See lib/strict_states/strict_hash.rb

The *INCLUDE WITH ARGUMENTS* paradigm:

* future-proof support for any/all state machines
* easily integrate with any state machine engine not already supported by this gem

Uses a method (StrictStates.checker) that returns a module (StrictStates::Checker) to accomplish this.

Defined Under Namespace

Modules: Checker Classes: StrictHash

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.checker(**config) ⇒ Object

Usage:

class MyModel < ActiveRecord::Base
  # ...
  # <<<===--- AFTER STATE MACHINE DEFINITION ---===>>>
  # ...
  include StrictStates.checker(
              klass: self,
              machines: {
                  state: :pluginaweek,
                  awesome_level: :pluginaweek,
                  bogus_level: ->(context, machine_name) {
                    context.state_machines[machine_name.to_sym].states.map(&:name)
                  }
              }
          )
end


37
38
39
40
41
42
# File 'lib/strict_states.rb', line 37

def self.checker(**config)
  validate_config(config)
  config[:machines] = states_for_machines(config[:klass], config[:machines])
  set_strict_state_lookup(config)
  ::StrictStates::Checker
end