Project

spank

0.0
No commit activity in last 3 years
No release in over 3 years
A lightweight ruby inversion of control (IOC) container
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 12.3
~> 3.1
~> 0.9
 Project Readme

Spank

A simple light weight inversion of control container written in ruby.

Build Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'spank'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spank

Usage

Register a single component and resolve it.

container = Spank::Container.new
container.register(:item) do |container|
  "ITEM"
end
item = container.resolve(:item)

Register multiple items, and resolve them.

container = Spank::Container.new
container.register(:pants) { jeans }
container.register(:pants) { dress_pants }
pants = container.resolve_all(:pants)

Register a singleton.

container = Spank::Container.new
container.register(:singleton) { fake }.as_singleton
single_instance = container.resolve(:singleton)
same_instance = container.resolve(:singleton)

Automatic dependency resolution.

class Child
  def initialize(mom,dad)
  end
end

container = Spank::Container.new
container.register(:mom) { mom }
container.register(:dad) { dad }
child = sut.build(Child)

Register selective interceptors.

class Interceptor
  def intercept(invocation)
    invocation.proceed
  end
end

class Command
  def run(input)
  end
end

container = Spank::Container.new
container
  .register(:command) { Command.new }
  .intercept(:run)
  .with(Interceptor.new)
proxy = container.resolve(:command)
proxy.run("hi")
container = Spank::Container.new
Spank::IOC.bind_to(container)
item = Spank::IOC.resolve(:item)

Enjoy!

Contributing

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