-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API: added a lookup within multiple namespaces
## Usage ```ruby Scope.namespaces << MyNamespace # => [nil, MyNamespace] Scope.for MyModel # => MyNamespace::MyScope ```
- Loading branch information
1 parent
cb27824
commit 32d1fa6
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Magic | ||
module Lookup | ||
module Namespaces | ||
attr_writer :namespaces | ||
|
||
def namespaces = @namespaces ||= [ nil ] | ||
|
||
def for object_class, *namespaces | ||
return super unless namespaces.empty? | ||
|
||
self.namespaces | ||
.reverse # recently added first | ||
.lazy # optimization | ||
.filter_map { super object_class, _1 } | ||
.first | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters