<commit_before>module DataMapper
  class Relationship
    module Builder

      class Has

        # Build a {OneToOne}, {OneToMany} or {ManyToMany} relationship
        #
        # @see Relationship::OneToMany
        # @see Relationship::OneToOne
        # @see Relationship::ManyToMany
        #
        # TODO: add specs
        #
        # @param [Mapper] source
        #   the mapper establishing this relationship
        #
        # @param [Fixnum, Range] cardinality
        #   the relationship's cardinality
        #
        # @param [Symbol] name
        #   the relationship's name
        #
        # @param [::Class] target_model
        #   the class of the object this relationship is pointing to
        #
        # @param [Hash] options
        #   the relationship's options
        #
        # @option options [Symbol, Array<Symbol>] :source_key
        #   the source_model's attributes to join on
        #
        # @option options [Symbol, Array<Symbol>] :target_key
        #   the target_model's attributes to join on
        #
        # @option options [Symbol] :through
        #   the name of the relationship to "go through" in case of M:N
        #
        # @return [OneToMany, OneToOne, ManyToMany]
        #
        # @api private
        def self.build(source, cardinality, name, target_model, options = {}, &op)
          via      = options[:through]
          min, max = extract_min_max(cardinality, name)

          options.update(:min => min, :max => max, :operation => op)

          klass =
            if max > 1
              if via
                Relationship::ManyToMany
              else
                Relationship::OneToMany
              end
            else
              Relationship::OneToOne
            end

          klass.new(name, source.model, target_model, options)
        end

        # Extract the upper and lower bounds from the given cardinality
        #
        # TODO: refactor<commit_msg>Rename local variable to better reflect its meaning<commit_after>module DataMapper
  class Relationship
    module Builder

      class Has

        # Build a {OneToOne}, {OneToMany} or {ManyToMany} relationship
        #
        # @see Relationship::OneToMany
        # @see Relationship::OneToOne
        # @see Relationship::ManyToMany
        #
        # TODO: add specs
        #
        # @param [Mapper] source
        #   the mapper establishing this relationship
        #
        # @param [Fixnum, Range] cardinality
        #   the relationship's cardinality
        #
        # @param [Symbol] name
        #   the relationship's name
        #
        # @param [::Class] target_model
        #   the class of the object this relationship is pointing to
        #
        # @param [Hash] options
        #   the relationship's options
        #
        # @option options [Symbol, Array<Symbol>] :source_key
        #   the source_model's attributes to join on
        #
        # @option options [Symbol, Array<Symbol>] :target_key
        #   the target_model's attributes to join on
        #
        # @option options [Symbol] :through
        #   the name of the relationship to "go through" in case of M:N
        #
        # @return [OneToMany, OneToOne, ManyToMany]
        #
        # @api private
        def self.build(source, cardinality, name, target_model, options = {}, &op)
          through  = options[:through]
          min, max = extract_min_max(cardinality, name)

          options.update(:min => min, :max => max, :operation => op)

          klass =
            if max > 1
              if through
                Relationship::ManyToMany
              else
                Relationship::OneToMany
              end
            else
              Relationship::OneToOne
            end

          klass.new(name, source.model, target_model, options)
        end

        # Extract the upper and lower bounds from the given cardinality
        #
        # TODO: refactor
{'fraction_non_alphanumeric': 0.08018154311649017, 'fraction_numerical': 0.0005042864346949068, 'mean_word_length': 1.6731805929919137, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3006706', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1004, 'n_words': 320}