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

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



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

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



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

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



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

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



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

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