bold 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.
data/lib/bold.rb CHANGED
@@ -1,5 +1,29 @@
1
1
  require "bold/version"
2
2
 
3
3
  module Bold
4
- # Your code goes here...
4
+ @suppliers = {}
5
+
6
+ def self.included(klass)
7
+ klass.extend(ClassMethods)
8
+ end
9
+
10
+ def self.supplies(need, &supplier)
11
+ @suppliers[need] = supplier
12
+ end
13
+
14
+ def self.supply(need)
15
+ @suppliers[need].call
16
+ end
17
+
18
+ def initialize(attributes={})
19
+ @supplies = attributes.delete(:supplies) || {}
20
+ end
21
+
22
+ module ClassMethods
23
+ def needs(need)
24
+ define_method(need) do
25
+ @supplies[need] ||= Bold.supply(need)
26
+ end
27
+ end
28
+ end
5
29
  end
data/lib/bold/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bold
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/bold_spec.rb CHANGED
@@ -1,7 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bold do
4
- it 'should have a version number' do
5
- Bold::VERSION.should_not be_nil
4
+ class Piano; end
5
+
6
+ Bold.supplies(:piano) { Piano.new }
7
+
8
+ class Bob
9
+ include Bold
10
+
11
+ needs :piano
12
+ attr_reader :attributes
13
+
14
+ def initialize(attributes={})
15
+ super
16
+ @attributes = attributes
17
+ end
18
+ end
19
+
20
+ subject do
21
+ Bob.new
22
+ end
23
+
24
+ its(:piano) { should be_a(Piano) }
25
+
26
+ context "when it is supplied Bach's lautenwerck" do
27
+ let(:lautenwerck) { double }
28
+
29
+ subject do
30
+ Bob.new(supplies: {
31
+ piano: lautenwerck
32
+ })
33
+ end
34
+
35
+ its(:piano) { should be(lautenwerck) }
36
+ its(:attributes) { should_not have_key(:supplies) }
6
37
  end
7
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: 675576305895653790
96
+ hash: -2640617838403457670
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 675576305895653790
105
+ hash: -2640617838403457670
106
106
  requirements: []
107
107
  rubyforge_project:
108
108
  rubygems_version: 1.8.25