Smithy
Smith is an Inversion of Control (IoC) container for Ruby. It's based on an example given in Jim Weirich's Dependency Injection: Vitally Important or Totally Irrelevant talk at O'REILLY OSCON 2005. He called the example matzdi_constructor so, presumably, Matz was involved as well.
Installation
Add this line to your application's Gemfile:
gem 'smithy'
And then execute:
$ bundle
Or install it yourself as:
$ gem install smithy
Usage
require "rubygems"
require "bundler/setup"
require "logger"
require "smithy"
class LoggingErrorReporter
def initialize(logger)
@logger = logger
end
def report(error)
@logger.error("badness: #{error}")
end
end
container = Smithy::Container.new
container.register(:logger, Logger.new($stdout)) # you can register literal objects
container.register(:error_reporter, LoggingErrorReporter, :logger) # you can also register classes
container.instance(:error_reporter).report("no more coffee")
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request