-
Notifications
You must be signed in to change notification settings - Fork 1
pythonandchips/depends-on
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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
About
simple dependency injection for ruby
Resources
Stars
Watchers
Forks
Packages 0
No packages published