<commit_before>require 'dry/core/constants'
require 'dry/core/class_attributes'

require 'rom/types'
require 'rom/initializer'
require 'rom/associations/name'

module ROM
  module Associations
    module Definitions
      # Abstract association definition object
      #
      # @api public
      class Abstract
        include Dry::Core::Constants
        include Dry::Equalizer(:source, :target, :result)
        extend Initializer
        extend Dry::Core::ClassAttributes

        defines :result

        # @!attribute [r] source
        #   @return [ROM::Relation::Name] the source relation name
        param :source

        # @!attribute [r] target
        #   @return [ROM::Relation::Name] the target relation name
        param :target

        # @!attribute [r] relation
        #   @return [Symbol] an optional relation identifier for the target
        option :relation, Types::Strict::Symbol, optional: true

        # @!attribute [r] result
        #   @return [Symbol] either :one or :many
        option :result, Types::Strict::Symbol, default: -> { self.class.result }

        # @!attribute [r] as
        #   @return [Symbol] an optional association alias name
        option :as, Types::Strict::Symbol, default: -> { target.to_sym }

        # @!attribute [r] foreign_key
        #   @return [Symbol] an optional association alias name
        option :foreign_key, Types::Optional::Strict::Symbol, optional: true

        # @!attribute [r] view
        #   @return [Symbol] An optional view that should be used to extend assoc relation
        option :view, optional: true

        # @!attribute [r] override
        #   @return [TrueClass,FalseClass] Whether custom view should override default one or not
        option :override, optional: true, default: -> { false }

        alias_method :name, :as

        # @api public
        def self.new(source, target, options = EMPTY_HASH)
          super(
            Name[source],
            Name[options[:relation] || target, target, options[:as] || target],
            options
          )
        end

        # @api public
        def override?
          options[:override].equal?(true)
        end

        # @api public
        def type
          Dry::Core::Inflector.demodulize(self.class.name).to_sym
        end
      end
    end
  end
end
<commit_msg>Clean up Associations::Definitions::Abstract.new and add docs<commit_after>require 'dry/core/constants'
require 'dry/core/class_attributes'

require 'rom/types'
require 'rom/initializer'
require 'rom/associations/name'

module ROM
  module Associations
    module Definitions
      # Abstract association definition object
      #
      # @api public
      class Abstract
        include Dry::Core::Constants
        include Dry::Equalizer(:source, :target, :result)
        extend Initializer
        extend Dry::Core::ClassAttributes

        defines :result

        # @!attribute [r] source
        #   @return [Associations::Name] the source relation name
        param :source

        # @!attribute [r] target
        #   @return [Associations::Name] the target relation name
        param :target

        # @!attribute [r] relation
        #   @return [Symbol] an optional relation identifier for the target
        option :relation, Types::Strict::Symbol, optional: true

        # @!attribute [r] result
        #   @return [Symbol] either :one or :many
        option :result, Types::Strict::Symbol, default: -> { self.class.result }

        # @!attribute [r] as
        #   @return [Symbol] an optional association alias name
        option :as, Types::Strict::Symbol, default: -> { target.to_sym }

        # @!attribute [r] foreign_key
        #   @return [Symbol] an optional association alias name
        option :foreign_key, Types::Optional::Strict::Symbol, optional: true

        # @!attribute [r] view
        #   @return [Symbol] An optional view that should be used to extend assoc relation
        option :view, optional: true

        # @!attribute [r] override
        #   @return [TrueClass,FalseClass] Whether custom view should override default one or not
        option :override, optional: true, default: -> { false }

        alias_method :name, :as

        # Instantiate a new association definition
        #
        # @param [Symbol] source The name of the source dataset
        # @param [Symbol] target The name of the target dataset
        # @param [Hash] options The option hash
        # @option options [Symbol] :as The name of the association (defaults to target)
        # @option options [Symbol] :relation The name of the target relation (defaults to target)
        # @option options [Symbol] :foreign_key The name of a custom foreign key
        # @option options [Symbol] :view The name of a custom relation view on the target's relation side
        # @option options [TrueClass,FalseClass] :override Whether provided :view should override association's default view
        #
        # @api public
        def self.new(source, target, options = EMPTY_HASH)
          super(Name[source], resolve_target_name(target, options), options)
        end

        # @api private
        def self.resolve_target_name(target, options)
          dataset = target
          relation = options.fetch(:relation, target)
          aliaz = options.fetch(:as, target)

          Name[relation, dataset, aliaz]
        end

        # @api public
        def override?
          options[:override].equal?(true)
        end

        # @api public
        def type
          Dry::Core::Inflector.demodulize(self.class.name).to_sym
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09529724933451642, 'fraction_numerical': 0.0, 'mean_word_length': 2.4033816425120773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6809110', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1464, 'n_words': 499}