Class: Statesman::Adapters::Memory
- Inherits:
-
Object
- Object
- Statesman::Adapters::Memory
- Defined in:
- lib/statesman/adapters/memory.rb
Instance Attribute Summary collapse
-
#parent_model ⇒ Object
readonly
Returns the value of attribute parent_model.
-
#transition_class ⇒ Object
readonly
Returns the value of attribute transition_class.
Instance Method Summary collapse
- #create(from, to, metadata = {}) ⇒ Object
- #history ⇒ Object
-
#initialize(transition_class, parent_model, observer, _opts = {}) ⇒ Memory
constructor
We only accept mode as a parameter to maintain a consistent interface with other adapters which require it.
- #last ⇒ Object
Constructor Details
#initialize(transition_class, parent_model, observer, _opts = {}) ⇒ Memory
We only accept mode as a parameter to maintain a consistent interface with other adapters which require it.
13 14 15 16 17 18 |
# File 'lib/statesman/adapters/memory.rb', line 13 def initialize(transition_class, parent_model, observer, _opts = {}) @history = [] @transition_class = transition_class @parent_model = parent_model @observer = observer end |
Instance Attribute Details
#parent_model ⇒ Object (readonly)
Returns the value of attribute parent_model.
9 10 11 |
# File 'lib/statesman/adapters/memory.rb', line 9 def parent_model @parent_model end |
#transition_class ⇒ Object (readonly)
Returns the value of attribute transition_class.
8 9 10 |
# File 'lib/statesman/adapters/memory.rb', line 8 def transition_class @transition_class end |
Instance Method Details
#create(from, to, metadata = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/statesman/adapters/memory.rb', line 20 def create(from, to, = {}) from = from.to_s to = to.to_s transition = transition_class.new(to, next_sort_key, ) @observer.execute(:before, from, to, transition) @history << transition @observer.execute(:after, from, to, transition) @observer.execute(:after_commit, from, to, transition) transition end |
#history ⇒ Object
36 37 38 |
# File 'lib/statesman/adapters/memory.rb', line 36 def history(*) @history end |
#last ⇒ Object
32 33 34 |
# File 'lib/statesman/adapters/memory.rb', line 32 def last(*) @history.max_by(&:sort_key) end |