Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 

README

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

Languages

You can’t perform that action at this time.