Sha256: 293d6dbfd4ad13c504fb5a78626ee46002b43f4a491f2de9a0d44452c7c46e3c

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'active_support/core_ext/hash/indifferent_access'
require 'method_decorators'
require 'method_decorators/decorators/precondition'

module Heracles
  module Wrapper
  end
end

class Heracles::Wrapper::NotificationResponse
  extend MethodDecorators
  attr_reader(
    :job_id,
    :job_status,
    :notification_payload,
    :one_time_notification_key
  )
  +Precondition.new { |params|
    params[:job_id] &&
    params[:job_status] &&
    params[:notification_payload].respond_to?(:to_hash)
  }
  def initialize(raw_params)
    params = HashWithIndifferentAccess.new(raw_params)
    @notification_payload = HashWithIndifferentAccess.new(params.fetch(:notification_payload))
    @job_id = params.fetch(:job_id).to_i
    @job_status = params.fetch(:job_status).to_sym
    @one_time_notification_key = params.fetch(:one_time_notification_key, nil)
  end

  def method_missing(method_name, *args, &block)
    super
  rescue NoMethodError
    @notification_payload.send(method_name, *args, &block)
  end

  def respond_to?(method_name)
    super || @notification_payload.respond_to?(method_name)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heracles-wrapper-0.0.3 lib/heracles-wrapper/notification_response.rb