diff options
| author | mo khan <mo@mokhan.ca> | 2013-12-27 11:04:52 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-12-27 11:04:52 -0700 |
| commit | 52a684c10f448b390d0458b4663be263b2be7bb3 (patch) | |
| tree | 85f29eb0d96fdbfc9f5651853c8a010ac395a007 | |
| parent | 4b6db81e24c4cdb09add78fffd52da5eda7c6e6d (diff) | |
move context and key to nasty.
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | lib/boot/bootstrap_container.rb | 4 | ||||
| -rw-r--r-- | lib/infrastructure/key.rb | 25 | ||||
| -rw-r--r-- | lib/infrastructure/simple_context.rb | 21 | ||||
| -rw-r--r-- | spec/specs/infrastructure/simple_context_spec.rb | 59 |
5 files changed, 3 insertions, 108 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 293371a..d67113f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -28,7 +28,7 @@ GEM multi_json (1.8.2) multi_xml (0.5.5) multipart-post (1.2.0) - nasty (0.0.1388166944) + nasty (0.0.1388167257) oauth2 (0.9.2) faraday (~> 0.8) httpauth (~> 0.2) diff --git a/lib/boot/bootstrap_container.rb b/lib/boot/bootstrap_container.rb index 900414e..9353d38 100644 --- a/lib/boot/bootstrap_container.rb +++ b/lib/boot/bootstrap_container.rb @@ -31,13 +31,13 @@ class BootstrapContainer end @container.register(:context) do #this should be scoped to each request - SimpleContext.new + Nasty::SimpleContext.new end.as_singleton @container.register(:session_factory) do session_factory end.as_singleton @container.register(:key) do - Key.new("database.session") + Nasty::Key.new("database.session") end.as_singleton Spank::IOC.bind_to(@container) end diff --git a/lib/infrastructure/key.rb b/lib/infrastructure/key.rb deleted file mode 100644 index 3bb757b..0000000 --- a/lib/infrastructure/key.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Key - def initialize(key) - @key = key - end - - def add_to(store, value) - store[to_sym] = value - end - - def remove_from(store) - store[to_sym] = nil - end - - def contained_in?(store) - item_from(store) - end - - def item_from(store) - store[to_sym] - end - - def to_sym - @key.to_sym - end -end diff --git a/lib/infrastructure/simple_context.rb b/lib/infrastructure/simple_context.rb deleted file mode 100644 index 01e1580..0000000 --- a/lib/infrastructure/simple_context.rb +++ /dev/null @@ -1,21 +0,0 @@ -class SimpleContext - def initialize(store = {}) - @store = store - end - - def add(key, value) - key.add_to(@store, value) - end - - def remove(key) - key.remove_from(@store) - end - - def contains?(key) - key.contained_in?(@store) - end - - def item_for(key) - key.item_from(@store) - end -end diff --git a/spec/specs/infrastructure/simple_context_spec.rb b/spec/specs/infrastructure/simple_context_spec.rb deleted file mode 100644 index 13e88d0..0000000 --- a/spec/specs/infrastructure/simple_context_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -require "spec_helper" - -describe SimpleContext do - let(:sut) { SimpleContext.new(store) } - let(:store) { Hash.new } - - context "when adding an item" do - let(:key) { Key.new("artist") } - let(:item) { "bobby digital" } - - before { sut.add(key, item) } - - it "should add the item to the context" do - store[key.to_sym].should == item - end - end - - context "when removing an item" do - let(:key) { Key.new("artist") } - let(:item) { "bobby digital" } - - before :each do - sut.add(key, item) - sut.remove(key) - end - - it "should remove the item from the store" do - store[key.to_sym].should be_nil - end - end - context "when checking if a key is in the context" do - context "when it is" do - let(:key) { Key.new("blah") } - before { sut.add(key, 'blah') } - let(:result) { sut.contains?(key) } - - it "should return true" do - result.should be_true - end - end - context "when it is not" do - let(:key) { Key.new("blah") } - let(:result) { sut.contains?(key) } - - it "should return false" do - result.should be_false - end - end - end - context "when retrieving an item" do - let(:key) { Key.new("name") } - before { sut.add(key, 'mo') } - let(:result) { sut.item_for(key) } - - it "should return the correct item" do - result.should == 'mo' - end - end -end |
