Class: Hanami::DB::Repo
- Inherits:
-
ROM::Repository
- Object
- ROM::Repository
- Hanami::DB::Repo
- Defined in:
- lib/hanami/db/repo.rb
Overview
Instance Attribute Summary collapse
- #root ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Repo
constructor
A new instance of Repo.
Constructor Details
#initialize ⇒ Repo
Returns a new instance of Repo.
36 37 38 39 40 41 42 43 44 |
# File 'lib/hanami/db/repo.rb', line 36 def initialize(*, **) super # Repos in Hanami apps infer a root from their class name (e.g. :posts for PostRepo). This # means _every_ repo ends up with an inferred root, many of which will not exist as # relations. To avoid errors from fetching these non-existent relations, check first before # setting the root. @root = set_relation(self.class.root) if set_relation?(self.class.root) end |
Instance Attribute Details
Class Method Details
.[](root) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/hanami/db/repo.rb', line 10 def self.[](root) fetch_or_store(root) do # Override ROM::Repository.[] logic to ensure repos with explicit roots inherit from # Hanami::DB::Repo itself, instead of the plain old ROM::Repository::Root. Class.new(self).tap { |klass| klass.root(root) } end end |
.inherited(klass) ⇒ 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.
29 30 31 32 |
# File 'lib/hanami/db/repo.rb', line 29 def self.inherited(klass) super klass.root(root) end |