Class: Hanami::Model::Associations::Dsl Private
- Inherits:
-
Object
- Object
- Hanami::Model::Associations::Dsl
- 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
Instance Method Summary collapse
- #belongs_to(relation) ⇒ Object private
- #has_many(relation, **args) ⇒ Object private
- #has_one(relation) ⇒ Object private
-
#initialize(repository, &blk) ⇒ Dsl
constructor
private
A new instance of Dsl.
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.
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.
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.
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.
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 |