module Tron::Resultable

Attributes

metadata[R]

Public Class Methods

included(receiver) click to toggle source
# File lib/tron/resultable.rb, line 5
def self.included(receiver)
  receiver.extend ::Tron::Resultable::ClassMethods
end
new(code: nil, metadata: nil) click to toggle source
# File lib/tron/resultable.rb, line 16
def initialize(code: nil, metadata: nil)
  @code     = code
  @metadata = metadata
  warn 'DEPRECATION WARNING: As of Tron 1.0.0 calls to `Tron::Success.call` and `Tron::Failure.call` are deprecated. ' \
       'They will be removed in Tron 2.0.0. Please migrate using `Tron.success` and `Tron.failure`. ' \
       "See github.com/halo/tron Called in:: `#{caller[2]}`"
end

Public Instance Methods

code() click to toggle source
# File lib/tron/resultable.rb, line 32
def code
  return if @code.to_s == ''

  @code.to_s.to_sym
end
failure?() click to toggle source
# File lib/tron/resultable.rb, line 28
def failure?
  is_a? ::Tron::Failure
end
meta() click to toggle source
# File lib/tron/resultable.rb, line 45
def meta
  if defined? ::Hashie::Mash
    metamash
  else
    metadata
  end
end
object() click to toggle source

Convenience Wrapper

# File lib/tron/resultable.rb, line 39
def object
  metadata[:object] || metadata['object']
rescue StandardError
  nil
end
success?() click to toggle source
# File lib/tron/resultable.rb, line 24
def success?
  is_a? ::Tron::Success
end

Private Instance Methods

metamash() click to toggle source
# File lib/tron/resultable.rb, line 55
def metamash
  if metadata.respond_to? :each_pair
    ::Hashie::Mash.new metadata
  elsif metadata
    metadata
  else
    ::Hashie::Mash.new
  end
end