Sha256: 83a54e55a508334ae2bd6af3235a0a44406472201e9cd32845333950341ce9ce

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

Gem.find_files('ledger_sync/serialization/type/**/*.rb').each { |path| require path }

module LedgerSync
  module Serialization
    class Attribute
      attr_reader :block,
                  :hash_attribute,
                  :if_method,
                  :resource_attribute,
                  :resource_class,
                  :type

      def initialize(args = {})
        @block              = args.fetch(:block, nil)
        @hash_attribute     = args.fetch(:hash_attribute, nil).try(:to_s)
        @resource_attribute = args.fetch(:resource_attribute, nil).try(:to_s)
        @resource_class     = args.fetch(:resource_class, nil)
        @type               = args.fetch(:type, nil) || LedgerSync::Type::Value.new
        @if_method          = args.fetch(:if, nil)
      end

      def block_value_for(args = {})
        block.call(args.merge(attribute: self))
      end

      def hash_attribute_dot_parts
        @hash_attribute_dot_parts ||= hash_attribute.split('.')
      end

      def reference?
        references_many? || references_one?
      end

      def resource_attribute_dot_parts
        @resource_attribute_dot_parts ||= resource_attribute.split('.')
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.5.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.4.4 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.3.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.2.3 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.2.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.2.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.0.2 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.0.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.0.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.8.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.8.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.7.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.6.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.5.2 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.5.1 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.5.0 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.4.4 lib/ledger_sync/serialization/attribute.rb
ledger_sync-1.4.2 lib/ledger_sync/serialization/attribute.rb