Sha256: 6e0b637bc29ffc095533cba15928fda94190ac418300f2c44e8f19350a513b57

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module ErpTools
  module Event
    module V0
      # A collection of methods for specifying the correct payload envelope to EventBridge
      # when communicating with the ERP
      # > Item.source
      # #=> 'mms.Item'
      # > Item.detail_types
      # #=> [:upsert]
      # > Item.detail_type :upsert
      # #=> "upsertItem"
      # > Item.detail_type :create
      # ErpTools::Event::UnsupportedEvent (key not found: :create)
      # > Item.payload_version
      # #=> "0"
      module Base
        PAYLOAD_VERSION = '0'

        def self.included(other)
          other.extend ClassMethods
        end

        module ClassMethods
          def detail_types
            self::DETAIL_TYPES.keys
          end

          def detail_type(name)
            self::DETAIL_TYPES.fetch(name.to_sym)
          rescue KeyError => err
            raise ::ErpTools::Event::UnsupportedEvent, err.message
          end

          def source
            self::SOURCE
          end

          def payload_version
            self::PAYLOAD_VERSION
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
erp_tools-0.3.0 lib/erp_tools/event/v0/base.rb
erp_tools-0.2.0 lib/erp_tools/event/v0/base.rb