Class: Statesman::Adapters::Memory
- Inherits:
-
Object
- Object
- Statesman::Adapters::Memory
- Defined in:
- lib/statesman/adapters/memory.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#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
-
#initialize(transition_class, parent_model, observer) ⇒ 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) ⇒ Memory
We only accept mode as a parameter to maintain a consistent interface with other adapters which require it.
12 13 14 15 16 17 |
# File 'lib/statesman/adapters/memory.rb', line 12 def initialize(transition_class, parent_model, observer) @history = [] @transition_class = transition_class @parent_model = parent_model @observer = observer end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
7 8 9 |
# File 'lib/statesman/adapters/memory.rb', line 7 def history @history end |
#parent_model ⇒ Object (readonly)
Returns the value of attribute parent_model.
8 9 10 |
# File 'lib/statesman/adapters/memory.rb', line 8 def parent_model @parent_model end |
#transition_class ⇒ Object (readonly)
Returns the value of attribute transition_class.
6 7 8 |
# File 'lib/statesman/adapters/memory.rb', line 6 def transition_class @transition_class end |
Instance Method Details
#create(from, to, metadata = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/statesman/adapters/memory.rb', line 19 def create(from, to, = {}) 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 |
#last ⇒ Object
29 30 31 |
# File 'lib/statesman/adapters/memory.rb', line 29 def last @history.sort_by(&:sort_key).last end |