Sha256: 85d15cb67cd61ccd796438606e925fef7ccc783a07edc383a597690d88b10070

Contents?: true

Size: 644 Bytes

Versions: 17

Compression:

Stored size: 644 Bytes

Contents

require 'ostruct'

module ActionLogic
  class ActionContext < OpenStruct
    SUCCESS = :success
    FAILURE = :failure
    HALTED  = :halted

    def initialize(params = {})
      params[:status] ||= SUCCESS
      super(params)
    end

    def update!(status, message)
      self.status = status
      self.message = message
    end

    def fail!(message = "")
      update!(FAILURE, message)
    end

    def halt!(message = "")
      update!(HALTED, message)
    end

    def success?
      self.status == SUCCESS
    end

    def failure?
      self.status == FAILURE
    end

    def halted?
      self.status == HALTED
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
action_logic-0.3.3 lib/action_logic/action_context.rb
action_logic-0.3.2 lib/action_logic/action_context.rb
action_logic-0.3.1 lib/action_logic/action_context.rb
action_logic-0.3.0 lib/action_logic/action_context.rb
action_logic-0.2.8 lib/action_logic/action_context.rb
action_logic-0.2.7 lib/action_logic/action_context.rb
action_logic-0.2.6 lib/action_logic/action_context.rb
action_logic-0.2.5 lib/action_logic/action_context.rb
action_logic-0.2.4 lib/action_logic/action_context.rb
action_logic-0.2.3 lib/action_logic/action_context.rb
action_logic-0.2.2 lib/action_logic/action_context.rb
action_logic-0.2.1 lib/action_logic/action_context.rb
action_logic-0.2.0 lib/action_logic/action_context.rb
action_logic-0.1.0 lib/action_logic/action_context.rb
action_logic-0.0.6 lib/action_logic/action_context.rb
action_logic-0.0.5 lib/action_logic/action_context.rb
action_logic-0.0.4 lib/action_logic/action_context.rb