Sha256: fe1733a5d1d6cd2c33c9e77f81acf7d5e67a1dea94c80a12b3dfdd38741488ab

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require_relative '../reference'

# Reference attribute type for has_one
module LedgerSync
  class ResourceAttribute
    class Reference
      class One < Reference
        module Mixin
          def self.included(base)
            base.extend(ClassMethods)
          end

          module ClassMethods
            def references_one(name, to: nil)
              to ||= begin
                require "#{inferred_config.root_path}/resources/#{name}"
                inferred_config.client_class.resources[name]
              end

              resource_attribute = ResourceAttribute::Reference::One.new(
                name: name,
                resource_class: self,
                to: to
              )
              resource_attributes.add resource_attribute
              _define_attribute_methods(name)
            end
          end
        end

        def initialize(args = {})
          to = args.fetch(:to)
          super(
            args.except(:to).merge(
              type: Type::ReferenceOne.new(resource_class: to)
            )
          )
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ledger_sync-3.0.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.6.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.5.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.4.4 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.3.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.2.3 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.2.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.2.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.0.2 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.0.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.0.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.8.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.8.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.7.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.6.0 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.5.2 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.5.1 lib/ledger_sync/resource_attribute/reference/one.rb
ledger_sync-1.5.0 lib/ledger_sync/resource_attribute/reference/one.rb