spank 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +24 -1
- data/README.md +86 -2
- data/Rakefile +6 -1
- data/lib/spank/version.rb +1 -1
- data/spank.gemspec +3 -1
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/container_spec.rb +28 -13
- data/spec/unit/ioc_spec.rb +19 -0
- metadata +19 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 304d66de564215dc7a9cbd7153f748de769a7615
         | 
| 4 | 
            +
              data.tar.gz: c7b0c3cf438d75a656b73b4f519c13de9a498d19
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9fe5f5ee9ee2702e28854e508f5ad76fefcafcf2bc0afd28a1aa4d55d4c128a1c4dd0f4e8309c30656745fc773bbb218bcd934729a39f1d31fde6dcb62ee81b9
         | 
| 7 | 
            +
              data.tar.gz: a490063b125cb26c2904575a9c74093277c61649c9e3472e82552d4731ff5db7354e406862a912aaa502c3bc05080f6879985bc31850b9226cc5339291b8fb8d
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,12 +1,32 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                spank (0.0. | 
| 4 | 
            +
                spank (0.0.2)
         | 
| 5 5 |  | 
| 6 6 | 
             
            GEM
         | 
| 7 7 | 
             
              remote: https://rubygems.org/
         | 
| 8 8 | 
             
              specs:
         | 
| 9 | 
            +
                developwithpassion_arrays (0.0.1)
         | 
| 10 | 
            +
                developwithpassion_fakes (0.1.1)
         | 
| 11 | 
            +
                  developwithpassion_arrays
         | 
| 12 | 
            +
                diff-lcs (1.2.4)
         | 
| 13 | 
            +
                multi_json (1.7.3)
         | 
| 9 14 | 
             
                rake (10.0.3)
         | 
| 15 | 
            +
                rspec (2.13.0)
         | 
| 16 | 
            +
                  rspec-core (~> 2.13.0)
         | 
| 17 | 
            +
                  rspec-expectations (~> 2.13.0)
         | 
| 18 | 
            +
                  rspec-mocks (~> 2.13.0)
         | 
| 19 | 
            +
                rspec-core (2.13.1)
         | 
| 20 | 
            +
                rspec-expectations (2.13.0)
         | 
| 21 | 
            +
                  diff-lcs (>= 1.1.3, < 2.0)
         | 
| 22 | 
            +
                rspec-fakes (0.0.9)
         | 
| 23 | 
            +
                  developwithpassion_fakes
         | 
| 24 | 
            +
                  rspec
         | 
| 25 | 
            +
                rspec-mocks (2.13.1)
         | 
| 26 | 
            +
                simplecov (0.7.1)
         | 
| 27 | 
            +
                  multi_json (~> 1.0)
         | 
| 28 | 
            +
                  simplecov-html (~> 0.7.1)
         | 
| 29 | 
            +
                simplecov-html (0.7.1)
         | 
| 10 30 |  | 
| 11 31 | 
             
            PLATFORMS
         | 
| 12 32 | 
             
              ruby
         | 
| @@ -14,4 +34,7 @@ PLATFORMS | |
| 14 34 | 
             
            DEPENDENCIES
         | 
| 15 35 | 
             
              bundler (~> 1.3)
         | 
| 16 36 | 
             
              rake
         | 
| 37 | 
            +
              rspec
         | 
| 38 | 
            +
              rspec-fakes
         | 
| 39 | 
            +
              simplecov
         | 
| 17 40 | 
             
              spank!
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # Spank
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            A simple light weight inversion of control container written in ruby.
         | 
| 4 4 |  | 
| 5 5 | 
             
            ## Installation
         | 
| 6 6 |  | 
| @@ -18,7 +18,91 @@ Or install it yourself as: | |
| 18 18 |  | 
| 19 19 | 
             
            ## Usage
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 21 | 
            +
            Register a single component and resolve it.
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ```ruby
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              container = Container.new
         | 
| 26 | 
            +
              container.register(:item) do
         | 
| 27 | 
            +
                "ITEM"
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
              container.register(:pants) { jeans }
         | 
| 30 | 
            +
              container.register(:pants) { dress_pants }
         | 
| 31 | 
            +
              item = container.resolve(:item)
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
            ```
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Register multiple items, and resolve them.
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ```ruby
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              container = Container.new
         | 
| 40 | 
            +
              container.register(:pants) { jeans }
         | 
| 41 | 
            +
              container.register(:pants) { dress_pants }
         | 
| 42 | 
            +
              pants = container.resolve_all(:item)
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
            ```
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            Register a singleton.
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            ```ruby
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              container = Container.new
         | 
| 51 | 
            +
              container.register(:singleton) { fake }.as_singleton
         | 
| 52 | 
            +
              single_instance = container.resolve(:singleton)
         | 
| 53 | 
            +
              same_instance = container.resolve(:singleton)
         | 
| 54 | 
            +
              
         | 
| 55 | 
            +
            ```
         | 
| 56 | 
            +
             | 
| 57 | 
            +
            Automatic dependency resolution.
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            ```ruby
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              class Child
         | 
| 62 | 
            +
                def initialize(mom,dad)
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
              end
         | 
| 65 | 
            +
              
         | 
| 66 | 
            +
              container = Container.new
         | 
| 67 | 
            +
              container.register(:mom) { mom }
         | 
| 68 | 
            +
              container.register(:dad) { dad }
         | 
| 69 | 
            +
              child = sut.build(Child)
         | 
| 70 | 
            +
                  
         | 
| 71 | 
            +
            ```
         | 
| 72 | 
            +
             | 
| 73 | 
            +
            Register selective interceptors.
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            ```ruby
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              class Interceptor
         | 
| 78 | 
            +
                def intercept(invocation)
         | 
| 79 | 
            +
                  invocation.proceed
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
              
         | 
| 83 | 
            +
              class Command
         | 
| 84 | 
            +
                def run(input)
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
              
         | 
| 88 | 
            +
              container = Container.new
         | 
| 89 | 
            +
              container.register(:command) { Command.new }.intercept(:run).with(Interceptor.new)
         | 
| 90 | 
            +
              proxy = container.resolve(:command)
         | 
| 91 | 
            +
              proxy.run("hi")
         | 
| 92 | 
            +
                  
         | 
| 93 | 
            +
            ```
         | 
| 94 | 
            +
             | 
| 95 | 
            +
            [Static gateway](http://codebetter.com/jpboodhoo/2007/10/15/the-static-gateway-pattern/) to connect to the container.
         | 
| 96 | 
            +
             | 
| 97 | 
            +
            ```ruby
         | 
| 98 | 
            +
              
         | 
| 99 | 
            +
              container = Container.new
         | 
| 100 | 
            +
              Spank::IOC.bind_to(container)
         | 
| 101 | 
            +
              Spank::IOC.resolve(:item)
         | 
| 102 | 
            +
                  
         | 
| 103 | 
            +
            ```
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            Enjoy!
         | 
| 22 106 |  | 
| 23 107 | 
             
            ## Contributing
         | 
| 24 108 |  | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/lib/spank/version.rb
    CHANGED
    
    
    
        data/spank.gemspec
    CHANGED
    
    | @@ -10,16 +10,18 @@ Gem::Specification.new do |spec| | |
| 10 10 | 
             
              spec.email         = ["mo@mokhan.ca"]
         | 
| 11 11 | 
             
              spec.description   = %q{A simple ruby container}
         | 
| 12 12 | 
             
              spec.summary       = %q{spank!}
         | 
| 13 | 
            -
              spec.homepage      = ""
         | 
| 13 | 
            +
              spec.homepage      = "http://github.com/mokhan/spank"
         | 
| 14 14 | 
             
              spec.license       = "MIT"
         | 
| 15 15 |  | 
| 16 16 | 
             
              spec.files         = `git ls-files`.split($/)
         | 
| 17 17 | 
             
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 18 | 
             
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
              spec.required_ruby_version = '>= 1.9.3'
         | 
| 20 21 |  | 
| 21 22 | 
             
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 22 23 | 
             
              spec.add_development_dependency "rake"
         | 
| 23 24 | 
             
              spec.add_development_dependency "rspec"
         | 
| 24 25 | 
             
              spec.add_development_dependency "rspec-fakes"
         | 
| 26 | 
            +
              spec.add_development_dependency "simplecov"
         | 
| 25 27 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        data/spec/unit/container_spec.rb
    CHANGED
    
    | @@ -6,69 +6,79 @@ module Spank | |
| 6 6 |  | 
| 7 7 | 
             
                describe "when resolving an item that has been registered" do
         | 
| 8 8 | 
             
                  let(:registered_item) { Object.new }
         | 
| 9 | 
            +
             | 
| 9 10 | 
             
                  before :each do
         | 
| 10 11 | 
             
                    sut.register(:item) do
         | 
| 11 12 | 
             
                      registered_item
         | 
| 12 13 | 
             
                    end
         | 
| 13 14 | 
             
                  end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 15 | 
            +
             | 
| 16 | 
            +
                  let(:result) { sut.resolve(:item) }
         | 
| 17 | 
            +
             | 
| 17 18 | 
             
                  it "should return the registered item" do
         | 
| 18 | 
            -
                     | 
| 19 | 
            +
                    result.should == registered_item
         | 
| 19 20 | 
             
                  end
         | 
| 20 21 | 
             
                end
         | 
| 22 | 
            +
             | 
| 21 23 | 
             
                describe "when resolving the container" do
         | 
| 22 24 | 
             
                  it "should return itself" do
         | 
| 23 25 | 
             
                    sut.resolve(:container).should == sut
         | 
| 24 26 | 
             
                  end
         | 
| 25 27 | 
             
                end
         | 
| 28 | 
            +
             | 
| 26 29 | 
             
                describe "when multiple items are registered with the same key" do
         | 
| 27 30 | 
             
                  let(:jeans) { fake }
         | 
| 28 31 | 
             
                  let(:dress_pants) { fake }
         | 
| 32 | 
            +
             | 
| 29 33 | 
             
                  before :each do
         | 
| 30 34 | 
             
                    sut.register(:pants) { jeans }
         | 
| 31 35 | 
             
                    sut.register(:pants) { dress_pants }
         | 
| 32 36 | 
             
                  end
         | 
| 37 | 
            +
             | 
| 33 38 | 
             
                  context "when resolving a single item" do
         | 
| 34 | 
            -
                     | 
| 35 | 
            -
             | 
| 36 | 
            -
                    end
         | 
| 39 | 
            +
                    let(:result) { sut.resolve(:pants) }
         | 
| 40 | 
            +
             | 
| 37 41 | 
             
                    it "should return the first one registered" do
         | 
| 38 | 
            -
                       | 
| 42 | 
            +
                      result.should == jeans
         | 
| 39 43 | 
             
                    end
         | 
| 40 44 | 
             
                  end
         | 
| 45 | 
            +
             | 
| 41 46 | 
             
                  context "when resolving all items" do
         | 
| 42 | 
            -
                     | 
| 43 | 
            -
             | 
| 44 | 
            -
                    end
         | 
| 47 | 
            +
                    let(:results) { sut.resolve_all(:pants)  }
         | 
| 48 | 
            +
             | 
| 45 49 | 
             
                    it "should return them all" do
         | 
| 46 | 
            -
                       | 
| 50 | 
            +
                      results.should == [jeans, dress_pants]
         | 
| 47 51 | 
             
                    end
         | 
| 48 52 | 
             
                  end
         | 
| 53 | 
            +
             | 
| 49 54 | 
             
                  context "when resolving all items for an unknown key" do
         | 
| 50 55 | 
             
                    it "should return an empty array" do
         | 
| 51 56 | 
             
                      sut.resolve_all(:shirts).should be_empty
         | 
| 52 57 | 
             
                    end
         | 
| 53 58 | 
             
                  end
         | 
| 54 59 | 
             
                end
         | 
| 60 | 
            +
             | 
| 55 61 | 
             
                context "when a component is registered as a singleton" do
         | 
| 56 62 | 
             
                  before :each do
         | 
| 57 63 | 
             
                    sut.register(:singleton) { fake }.as_singleton
         | 
| 58 64 | 
             
                  end
         | 
| 65 | 
            +
             | 
| 59 66 | 
             
                  it "should return the same instance of that component each time it is resolved" do
         | 
| 60 67 | 
             
                    sut.resolve(:singleton).should == sut.resolve(:singleton)
         | 
| 61 68 | 
             
                  end
         | 
| 62 69 | 
             
                end
         | 
| 70 | 
            +
             | 
| 63 71 | 
             
                context "when invoking the factory method" do
         | 
| 64 72 | 
             
                  before :each do
         | 
| 65 73 | 
             
                    sut.register(:item){ |item| @result = item }
         | 
| 66 74 | 
             
                    sut.resolve(:item)
         | 
| 67 75 | 
             
                  end
         | 
| 76 | 
            +
             | 
| 68 77 | 
             
                  it "should pass the container through to the block" do
         | 
| 69 78 | 
             
                    @result.should == sut
         | 
| 70 79 | 
             
                  end
         | 
| 71 80 | 
             
                end
         | 
| 81 | 
            +
             | 
| 72 82 | 
             
                context "when automatically resolving dependencies" do
         | 
| 73 83 | 
             
                  class Child
         | 
| 74 84 | 
             
                    def initialize(mom,dad)
         | 
| @@ -80,20 +90,24 @@ module Spank | |
| 80 90 | 
             
                  context "when the dependencies have been registered" do
         | 
| 81 91 | 
             
                    let(:mom) { fake }
         | 
| 82 92 | 
             
                    let(:dad) { fake }
         | 
| 93 | 
            +
             | 
| 83 94 | 
             
                    before :each do
         | 
| 84 95 | 
             
                      sut.register(:mom) { mom }
         | 
| 85 96 | 
             
                      sut.register(:dad) { dad }
         | 
| 86 97 | 
             
                    end
         | 
| 98 | 
            +
             | 
| 87 99 | 
             
                    it "should be able to glue the pieces together automatically" do
         | 
| 88 100 | 
             
                      sut.build(Child).should be_a_kind_of(Child)
         | 
| 89 101 | 
             
                    end
         | 
| 90 102 | 
             
                  end
         | 
| 103 | 
            +
             | 
| 91 104 | 
             
                  context "when a component cannot automatically be constructed" do
         | 
| 92 105 | 
             
                    it "should raise an error" do
         | 
| 93 106 | 
             
                      expect { sut.build(Child) }.to raise_error(ContainerError)
         | 
| 94 107 | 
             
                    end
         | 
| 95 108 | 
             
                  end
         | 
| 96 109 | 
             
                end
         | 
| 110 | 
            +
             | 
| 97 111 | 
             
                context "when registering an interceptor" do
         | 
| 98 112 | 
             
                  class TestInterceptor
         | 
| 99 113 | 
             
                    attr_reader :called
         | 
| @@ -102,6 +116,7 @@ module Spank | |
| 102 116 | 
             
                      invocation.proceed
         | 
| 103 117 | 
             
                    end
         | 
| 104 118 | 
             
                  end
         | 
| 119 | 
            +
             | 
| 105 120 | 
             
                  class TestCommand
         | 
| 106 121 | 
             
                    attr_reader :called, :received
         | 
| 107 122 | 
             
                    def run(input)
         | 
| @@ -109,6 +124,7 @@ module Spank | |
| 109 124 | 
             
                      @received = input
         | 
| 110 125 | 
             
                    end
         | 
| 111 126 | 
             
                  end
         | 
| 127 | 
            +
             | 
| 112 128 | 
             
                  let(:command) { TestCommand.new }
         | 
| 113 129 | 
             
                  let(:interceptor) { TestInterceptor.new }
         | 
| 114 130 |  | 
| @@ -122,7 +138,6 @@ module Spank | |
| 122 138 | 
             
                  end
         | 
| 123 139 |  | 
| 124 140 | 
             
                  it "should forward the args to the command" do
         | 
| 125 | 
            -
                    #command.should have_received(:run, 'hi')
         | 
| 126 141 | 
             
                    command.called.should be_true
         | 
| 127 142 | 
             
                    command.received.should == ['hi']
         | 
| 128 143 | 
             
                  end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Spank::IOC do
         | 
| 4 | 
            +
              context "when bound to a container" do
         | 
| 5 | 
            +
                let(:container) { fake }
         | 
| 6 | 
            +
                let(:component) { fake }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                before :each do
         | 
| 9 | 
            +
                  container.stub(:resolve).with(:idbconnection).and_return(component)
         | 
| 10 | 
            +
                  Spank::IOC.bind_to(container)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                let(:result) { Spank::IOC.resolve(:idbconnection) }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                it "should resove items from that container" do
         | 
| 16 | 
            +
                  result.should == component
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: spank
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - mo khan
         | 
| @@ -66,6 +66,20 @@ dependencies: | |
| 66 66 | 
             
                - - '>='
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 68 | 
             
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: simplecov
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - '>='
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - '>='
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 69 83 | 
             
            description: A simple ruby container
         | 
| 70 84 | 
             
            email:
         | 
| 71 85 | 
             
            - mo@mokhan.ca
         | 
| @@ -93,8 +107,9 @@ files: | |
| 93 107 | 
             
            - spank.gemspec
         | 
| 94 108 | 
             
            - spec/spec_helper.rb
         | 
| 95 109 | 
             
            - spec/unit/container_spec.rb
         | 
| 110 | 
            +
            - spec/unit/ioc_spec.rb
         | 
| 96 111 | 
             
            - spec/unit/proxy_spec.rb
         | 
| 97 | 
            -
            homepage:  | 
| 112 | 
            +
            homepage: http://github.com/mokhan/spank
         | 
| 98 113 | 
             
            licenses:
         | 
| 99 114 | 
             
            - MIT
         | 
| 100 115 | 
             
            metadata: {}
         | 
| @@ -106,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 106 121 | 
             
              requirements:
         | 
| 107 122 | 
             
              - - '>='
         | 
| 108 123 | 
             
                - !ruby/object:Gem::Version
         | 
| 109 | 
            -
                  version:  | 
| 124 | 
            +
                  version: 1.9.3
         | 
| 110 125 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 111 126 | 
             
              requirements:
         | 
| 112 127 | 
             
              - - '>='
         | 
| @@ -121,4 +136,5 @@ summary: spank! | |
| 121 136 | 
             
            test_files:
         | 
| 122 137 | 
             
            - spec/spec_helper.rb
         | 
| 123 138 | 
             
            - spec/unit/container_spec.rb
         | 
| 139 | 
            +
            - spec/unit/ioc_spec.rb
         | 
| 124 140 | 
             
            - spec/unit/proxy_spec.rb
         |