-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
32 lines (19 loc) · 1.07 KB
/
README
File metadata and controls
32 lines (19 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Depends on, (very) simple dependency injection for ruby
=======================================================
Dependency injection in most static languages is used to break dependencies between object and layers.
Now Ruby as a language is loosely coupled but that doesn't mean it can benefit from some simple dependency injection, and depends on tries to do this.
To add dependencies simply add depends_on and a list of dependencies. The dependencies will be added to you class so you can call them when ever you like
Examples
class MyAwesomeClass
depends_on :a_nother_class
def some_awesome_method
a_nother_class.do_something_awesome
end
end
With factory methods
class MyAwesomeClass < ActiveRecord::Base
depends_on :a_nother_class => lambda{ |owner| owner.country == "UK" ? UKTaxCalculator.new : WorldTaxCalculator.new }
end
Future work
Ideal this should make testing that wee bit easier allowing you to substitute fakes when you want to.
NOTE: this is a very early push mainly to get some feedback. Please send me a message with comments/love/hate/indifference