Sha256: 66e4eccb970a329a2ee604b89f222358bcf64248e90821099240aac2d6eebde2

Contents?: true

Size: 931 Bytes

Versions: 1

Compression:

Stored size: 931 Bytes

Contents

module Hanami
  module Model
    module Associations
      # Auto-infer relations linked to repository's associations
      #
      # @since 0.7.0
      # @api private
      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

        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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-model-1.1.0.beta1 lib/hanami/model/associations/dsl.rb