simple dependency injection for ruby
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
README
Rakefile
depends_on.gemspec

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