Sha256: 0682b11b15114e378b21e5576a99830aab8a00a0510db493d55bc44e7867d3c2

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

module Hanami
  module Model
    module Associations
      # Auto-infer relations linked to repository's associations
      #
      # @since 0.7.0
      # @api private
      #
      # rubocop:disable Naming/PredicateName
      class Dsl
        # @since 0.7.0
        # @api private
        def initialize(repository, &blk)
          @repository = repository
          instance_eval(&blk)
        end

        # @since 0.7.0
        # @api private
        def has_many(relation, **args)
          @repository.__send__(:relations, relation)
          @repository.__send__(:relations, args[:through]) if args[:through]
        end

        # @since 1.1.0
        # @api private
        def has_one(relation, *)
          @repository.__send__(:relations, Hanami::Utils::String.pluralize(relation).to_sym)
        end

        # @since 1.1.0
        # @api private
        def belongs_to(relation, *)
          @repository.__send__(:relations, Hanami::Utils::String.pluralize(relation).to_sym)
        end
      end
      # rubocop:enable Naming/PredicateName
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hanami-model-1.3.2 lib/hanami/model/associations/dsl.rb
hanami-model-1.3.1 lib/hanami/model/associations/dsl.rb
hanami-model-1.3.0 lib/hanami/model/associations/dsl.rb
hanami-model-1.3.0.beta1 lib/hanami/model/associations/dsl.rb
hanami-model-1.2.0 lib/hanami/model/associations/dsl.rb
hanami-model-1.2.0.rc2 lib/hanami/model/associations/dsl.rb
hanami-model-1.2.0.rc1 lib/hanami/model/associations/dsl.rb
hanami-model-1.2.0.beta2 lib/hanami/model/associations/dsl.rb
hanami-model-1.2.0.beta1 lib/hanami/model/associations/dsl.rb
hanami-model-1.1.0 lib/hanami/model/associations/dsl.rb
hanami-model-1.1.0.rc1 lib/hanami/model/associations/dsl.rb
hanami-model-1.1.0.beta3 lib/hanami/model/associations/dsl.rb
hanami-model-1.1.0.beta2 lib/hanami/model/associations/dsl.rb