class Statesman::Adapters::Memory

Attributes

parent_model[R]
transition_class[R]

Public Class Methods

new(transition_class, parent_model, observer, _opts = {}) click to toggle source

We only accept mode as a parameter to maintain a consistent interface with other adapters which require it.

# 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

Public Instance Methods

create(from, to, metadata = {}) click to toggle source
# File lib/statesman/adapters/memory.rb, line 20
def create(from, to, metadata = {})
  from = from.to_s
  to = to.to_s
  transition = transition_class.new(to, next_sort_key, metadata)

  @observer.execute(:before, from, to, transition)
  @history << transition
  @observer.execute(:after, from, to, transition)
  @observer.execute(:after_commit, from, to, transition)
  transition
end
history(*) click to toggle source
# File lib/statesman/adapters/memory.rb, line 36
def history(*)
  @history
end
last(*) click to toggle source
# File lib/statesman/adapters/memory.rb, line 32
def last(*)
  @history.max_by(&:sort_key)
end
reset() click to toggle source
# File lib/statesman/adapters/memory.rb, line 40
def reset
  @history = []
end

Private Instance Methods

next_sort_key() click to toggle source
# File lib/statesman/adapters/memory.rb, line 46
def next_sort_key
  (last && last.sort_key + 10) || 10
end