Skip to content

pvenable/smithy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%