Class: Hanami::Model::Associations::Dsl Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/model/associations/dsl.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Auto-infer relations linked to repository's associations

rubocop:disable Naming/PredicateName

Since:

  • 0.7.0

Instance Method Summary collapse

Constructor Details

#initialize(repository, &blk) ⇒ Dsl

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Dsl.

Since:

  • 0.7.0


13
14
15
16
# File 'lib/hanami/model/associations/dsl.rb', line 13

def initialize(repository, &blk)
  @repository = repository
  instance_eval(&blk)
end

Instance Method Details

#belongs_to(relation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


33
34
35
# File 'lib/hanami/model/associations/dsl.rb', line 33

def belongs_to(relation, *)
  @repository.__send__(:relations, Hanami::Utils::String.pluralize(relation).to_sym)
end

#has_many(relation, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.7.0


20
21
22
23
# File 'lib/hanami/model/associations/dsl.rb', line 20

def has_many(relation, **args)
  @repository.__send__(:relations, relation)
  @repository.__send__(:relations, args[:through]) if args[:through]
end

#has_one(relation) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.1.0


27
28
29
# File 'lib/hanami/model/associations/dsl.rb', line 27

def has_one(relation, *)
  @repository.__send__(:relations, Hanami::Utils::String.pluralize(relation).to_sym)
end