gister 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,19 @@ require 'faraday'
2
2
 
3
3
  module Gister
4
4
  class Fetcher
5
+ class MemoryStore
6
+ def initialize; @store = Hash.new; end
7
+ def set(k,v); @store[k]=v; end
8
+ def get(k); @store[k]; end
9
+ end
10
+
5
11
  ClientError = Class.new(StandardError)
6
12
  GistNotFound = Class.new(ClientError)
7
13
 
8
- def initialize
9
- @store = Hash.new
14
+ attr_writer :store
15
+
16
+ def initialize(store = MemoryStore.new)
17
+ @store = store
10
18
  end
11
19
 
12
20
  def fetch(key)
@@ -18,16 +26,19 @@ module Gister
18
26
  result
19
27
  end
20
28
  end
29
+
30
+ def get(k); @store.get(cache_bust(k)); end
31
+ def set(k, v); @store.set(cache_bust(k), v); end
21
32
 
22
- def get(key)
23
- @store[key]
33
+ private
34
+
35
+ def cache_bust(key)
36
+ cache_buster + key
24
37
  end
25
38
 
26
- def set(key, value)
27
- @store[key] = value
39
+ def cache_buster
40
+ ENV['CACHE_BUSTER'].to_s
28
41
  end
29
-
30
- private
31
42
 
32
43
  def fetch_result(key)
33
44
  path, params = parse_uri(key)
@@ -1,3 +1,3 @@
1
1
  module Gister
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -12,6 +12,14 @@ describe Gister::Fetcher do
12
12
  subject.set(key, "hello")
13
13
  subject.get(key).should == "hello"
14
14
  end
15
+
16
+ it "should bust the cache if the ENV changes" do
17
+ subject.set key, "hello"
18
+ ENV["CACHE_BUSTER"] = "1"
19
+ subject.get(key).should == nil
20
+ subject.set key, "hello"
21
+ subject.get(key).should == "hello"
22
+ end
15
23
  end
16
24
 
17
25
  describe "fetch" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gister
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:
@@ -13,7 +13,7 @@ date: 2012-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70220136504780 !ruby/object:Gem::Requirement
16
+ requirement: &70107306352080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70220136504780
24
+ version_requirements: *70107306352080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: vcr
27
- requirement: &70220136503880 !ruby/object:Gem::Requirement
27
+ requirement: &70107306351200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70220136503880
35
+ version_requirements: *70107306351200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: webmock
38
- requirement: &70220136503320 !ruby/object:Gem::Requirement
38
+ requirement: &70107306350640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70220136503320
46
+ version_requirements: *70107306350640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &70220136502740 !ruby/object:Gem::Requirement
49
+ requirement: &70107306350060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.6.1
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70220136502740
57
+ version_requirements: *70107306350060
58
58
  description: Provides a Middleware to cache embedded gist content
59
59
  email:
60
60
  - rubymaverick@gmail.com