nasty 0.0.1388166944 → 0.0.1388167257

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89915476bb30d44f78e092da9916dcd1f9cc0d4e
4
- data.tar.gz: 00271ed65c769440f8c2df1600933405e31f19f6
3
+ metadata.gz: 561d541ea6858383d1bd1c5d0bb3506442466d6a
4
+ data.tar.gz: 7095e04b44b7166922564b6fa16518a2330c5104
5
5
  SHA512:
6
- metadata.gz: 4163f06eaa5b09d03ecfb900ec4321d9b0150090a54d0d2fc6d0c46b30adcdb466b2c36f464e72a3f237e4baa2f8dacf67dc60cfe55cb95cb04ab7799da3175e
7
- data.tar.gz: 30be1f9fe89b9879e7b2761cf9911601859ddef531ebb764352c50a7b2e8ad649530cdf1c6e4f78187f842eee8ae5dee50657111433c19cfdd3be81bfbbdaf27
6
+ metadata.gz: a8beedef9e079841f366a6510116aa62875371f20d21de1b9dd8496d39202a767ffdde6f50d35a5ed8cbc0b6da38244211a9eeeb6e893f9fe03e65b4c5e0bd2f
7
+ data.tar.gz: 66ef31ef012d5f9dfa7d0f79f4ae948598388cf8ae48ad6bbf805ac5075a0d8630b4143acccc420aa8ac1cc8c17169d7a35166d561b1b556fc1d67940ab2d6fa
data/lib/nasty.rb CHANGED
@@ -5,10 +5,12 @@ require "nasty/composite_command"
5
5
  require "nasty/expose_binding"
6
6
  require "nasty/identity_map"
7
7
  require "nasty/kernel"
8
+ require "nasty/key"
8
9
  require "nasty/lambda_behaviours"
9
10
  require "nasty/lazy"
10
11
  require "nasty/log"
11
12
  require "nasty/object"
13
+ require "nasty/simple_context"
12
14
  require "nasty/version"
13
15
 
14
16
  module Nasty
data/lib/nasty/key.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Nasty
2
+ class Key
3
+ def initialize(key)
4
+ @key = key
5
+ end
6
+
7
+ def add_to(store, value)
8
+ store[to_sym] = value
9
+ end
10
+
11
+ def remove_from(store)
12
+ store[to_sym] = nil
13
+ end
14
+
15
+ def contained_in?(store)
16
+ item_from(store)
17
+ end
18
+
19
+ def item_from(store)
20
+ store[to_sym]
21
+ end
22
+
23
+ def to_sym
24
+ @key.to_sym
25
+ end
26
+ end
27
+ end
data/lib/nasty/lazy.rb CHANGED
@@ -11,7 +11,7 @@ module Nasty
11
11
  end
12
12
 
13
13
  class << self
14
- def bind_resolver(&block)
14
+ def bind_factory(&block)
15
15
  @@factory = block
16
16
  end
17
17
 
@@ -0,0 +1,23 @@
1
+ module Nasty
2
+ class SimpleContext
3
+ def initialize(store = {})
4
+ @store = store
5
+ end
6
+
7
+ def add(key, value)
8
+ key.add_to(@store, value)
9
+ end
10
+
11
+ def remove(key)
12
+ key.remove_from(@store)
13
+ end
14
+
15
+ def contains?(key)
16
+ key.contained_in?(@store)
17
+ end
18
+
19
+ def item_for(key)
20
+ key.item_from(@store)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+
3
+ module Nasty
4
+ describe SimpleContext do
5
+ let(:sut) { SimpleContext.new(store) }
6
+ let(:store) { Hash.new }
7
+
8
+ context "when adding an item" do
9
+ let(:key) { Key.new("artist") }
10
+ let(:item) { "bobby digital" }
11
+
12
+ before { sut.add(key, item) }
13
+
14
+ it "should add the item to the context" do
15
+ store[key.to_sym].should == item
16
+ end
17
+ end
18
+
19
+ context "when removing an item" do
20
+ let(:key) { Key.new("artist") }
21
+ let(:item) { "bobby digital" }
22
+
23
+ before :each do
24
+ sut.add(key, item)
25
+ sut.remove(key)
26
+ end
27
+
28
+ it "should remove the item from the store" do
29
+ store[key.to_sym].should be_nil
30
+ end
31
+ end
32
+
33
+ context "when checking if a key is in the context" do
34
+ context "when it is" do
35
+ let(:key) { Key.new("blah") }
36
+ before { sut.add(key, 'blah') }
37
+ let(:result) { sut.contains?(key) }
38
+
39
+ it "should return true" do
40
+ result.should be_true
41
+ end
42
+ end
43
+
44
+ context "when it is not" do
45
+ let(:key) { Key.new("blah") }
46
+ let(:result) { sut.contains?(key) }
47
+
48
+ it "should return false" do
49
+ result.should be_false
50
+ end
51
+ end
52
+ end
53
+ context "when retrieving an item" do
54
+ let(:key) { Key.new("name") }
55
+ before { sut.add(key, 'mo') }
56
+ let(:result) { sut.item_for(key) }
57
+
58
+ it "should return the correct item" do
59
+ result.should == 'mo'
60
+ end
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1388166944
4
+ version: 0.0.1388167257
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
@@ -87,10 +87,12 @@ files:
87
87
  - lib/nasty/expose_binding.rb
88
88
  - lib/nasty/identity_map.rb
89
89
  - lib/nasty/kernel.rb
90
+ - lib/nasty/key.rb
90
91
  - lib/nasty/lambda_behaviours.rb
91
92
  - lib/nasty/lazy.rb
92
93
  - lib/nasty/log.rb
93
94
  - lib/nasty/object.rb
95
+ - lib/nasty/simple_context.rb
94
96
  - lib/nasty/version.rb
95
97
  - nasty.gemspec
96
98
  - spec/spec_helper.rb
@@ -101,6 +103,7 @@ files:
101
103
  - spec/unit/lambda_behaviours_spec.rb
102
104
  - spec/unit/lazy_spec.rb
103
105
  - spec/unit/log_spec.rb
106
+ - spec/unit/simple_context_spec.rb
104
107
  - spec/unit/using_spec.rb
105
108
  homepage: http://github.com/mokhan/nasty
106
109
  licenses:
@@ -135,4 +138,5 @@ test_files:
135
138
  - spec/unit/lambda_behaviours_spec.rb
136
139
  - spec/unit/lazy_spec.rb
137
140
  - spec/unit/log_spec.rb
141
+ - spec/unit/simple_context_spec.rb
138
142
  - spec/unit/using_spec.rb