Sha256: 1784e13f66f014e339014831af4a0fd282ce11dd64db735b6d99659fce196b00

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

module Clowne
  module Adapters # :nodoc: all
    class ActiveRecord
      class UnknownAssociation < StandardError; end

      class Association
        class << self
          def call(source, record, declaration, params:)
            reflection = source.class.reflections[declaration.name.to_s]

            if reflection.nil?
              raise UnknownAssociation,
                    "Association #{declaration.name} couldn't be found for #{source.class}"
            end

            cloner_class = Associations.cloner_for(reflection)

            cloner_class.new(reflection, source, declaration, params).call(record)

            record
          end
        end
      end
    end
  end
end

Clowne::Adapters::ActiveRecord.register_resolver(
  :association,
  Clowne::Adapters::ActiveRecord::Association,
  before: :nullify
)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clowne-0.1.0.beta1 lib/clowne/adapters/active_record/association.rb
clowne-0.1.0.pre1 lib/clowne/adapters/active_record/association.rb