Sha256: 9a2fd1abd3da7eda3a95bf20dcc53577bd9d3e06b1ee43a9322e9285054991c1

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require_relative '../mixins/delegate_iterable_methods_mixin'

module LedgerSync
  module Util
    class ResourceConverter
      class AttributeSet
        include Mixins::DelegateIterableMethodsMixin

        attr_reader :attributes,
                    :resource_converter_class

        delegate_array_methods_to :attributes

        def initialize(args = {})
          @attributes               = []
          @attribute_keys           = {}
          @resource_converter_class = args.fetch(:resource_converter_class)
        end

        def add(attribute)
          unless attribute.destination_attribute.nil?
            if @attribute_keys.key?(attribute.destination_attribute.to_s)
              raise "destination_attribute already defined for #{resource_converter_class.name}: #{attribute.destination_attribute}"
            end

            @attribute_keys[attribute.destination_attribute] = attribute
          end

          attributes << attribute

          attribute
        end

        def hash_attribute?(key)
          hash_attribute_keyed_hash.include?(key.to_s)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.4.2 lib/ledger_sync/util/resource_converter/attribute_set.rb
ledger_sync-1.4.1 lib/ledger_sync/util/resource_converter/attribute_set.rb
ledger_sync-1.4.0 lib/ledger_sync/util/resource_converter/attribute_set.rb