Sha256: 7eaca44ddb476d9aed30fe2798b798e068ebc5d6119ebeeb1eef01e8e5b97557

Contents?: true

Size: 929 Bytes

Versions: 21

Compression:

Stored size: 929 Bytes

Contents

class MessageStateMachine
  include Statesman::Machine

  state :pending, initial: true
  state :unread
  state :read

  transition from: :pending, to: :unread
  transition from: :pending, to: :read
  transition from: :unread, to: :read
  transition from: :read, to: :unread

  before_transition(from: :pending, to: :read) do |message|
    message.read_at = Time.zone.now unless message.read_at
  end

  before_transition(from: :unread, to: :read) do |message|
    message.read_at = Time.zone.now unless message.read_at
  end

  before_transition(from: :read, to: :unread) do |message|
    message.read_at = nil
  end

  after_transition(from: :pending, to: :read) do |message|
    message.index
    Sunspot.commit
  end

  after_transition(from: :unread, to: :read) do |message|
    message.index
    Sunspot.commit
  end

  after_transition(from: :read, to: :unread) do |message|
    message.index
    Sunspot.commit
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
enju_message-0.3.4 app/models/message_state_machine.rb
enju_message-0.3.3 app/models/message_state_machine.rb
enju_message-0.4.0.rc.1 app/models/message_state_machine.rb
enju_message-0.3.2 app/models/message_state_machine.rb
enju_message-0.4.0.beta.2 app/models/message_state_machine.rb
enju_message-0.4.0.beta.1 app/models/message_state_machine.rb
enju_message-0.3.1 app/models/message_state_machine.rb
enju_message-0.3.0 app/models/message_state_machine.rb
enju_message-0.3.0.rc.1 app/models/message_state_machine.rb
enju_message-0.3.0.beta.1 app/models/message_state_machine.rb
enju_message-0.2.4 app/models/message_state_machine.rb
enju_message-0.2.3 app/models/message_state_machine.rb
enju_message-0.2.2 app/models/message_state_machine.rb
enju_message-0.2.1 app/models/message_state_machine.rb
enju_message-0.2.0 app/models/message_state_machine.rb
enju_message-0.2.0.beta.5 app/models/message_state_machine.rb
enju_message-0.2.0.beta.4 app/models/message_state_machine.rb
enju_message-0.2.0.beta.3 app/models/message_state_machine.rb
enju_message-0.2.0.beta.2 app/models/message_state_machine.rb
enju_message-0.2.0.beta.1 app/models/message_state_machine.rb