-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise exception when injecting into modules
To me it happened that I accidentally injected my dependencies into a namespace module instead of into a class, like this: module Operations module Articles include Import["repositories.articles"] class Create # ... end end end When I did that, I got a NoMethodError for NilClass somewhere down the line. This led me to believe that I've somehow incorrectly passed parameters to `Import[]`, and it took me a while to realize what was the error. The error occurred because the downstream code assumes the #initialize method will be defined, which is not the case for modules. To improve the developer experience, we detect that we're attempting to inject into a module and raise an explicit exception.
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dry | ||
module AutoInject | ||
Error = Class.new(StandardError) | ||
DuplicateDependencyError = Class.new(Error) | ||
DependencyNameInvalid = Class.new(Error) | ||
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
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