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.
11 12 13 14 15 16 |
# File 'lib/statesman/adapters/memory.rb', line 11 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.
7 8 9 |
# File 'lib/statesman/adapters/memory.rb', line 7 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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/statesman/adapters/memory.rb', line 18 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
34 35 36 |
# File 'lib/statesman/adapters/memory.rb', line 34 def history(*) @history end |
#last ⇒ Object
30 31 32 |
# File 'lib/statesman/adapters/memory.rb', line 30 def last(*) @history.max_by(&:sort_key) end |