coffee_table 0.2.12 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fee2e1ac835d575263dd819e6fd16b08ea050767
4
- data.tar.gz: 51f4a70b7b890bc9d84b2249ac0dc3479985c335
2
+ SHA256:
3
+ metadata.gz: fc2112aca3d10eefa5cbdc4996ee4e31fba80c16fd9900e2f8db7b63fb45039e
4
+ data.tar.gz: d1fa15f13c2d8eceaa5a197dd3adb7890c2279a52855f9ded03deaf73ddbc784
5
5
  SHA512:
6
- metadata.gz: b0cad5dbb073a07ce1a78af5376deb303eb1f7a128c1c2c73d75ea89f589f8515a537fb59cb7c85799ad0b0174744a3a45e1bd0ba1718afb2cce19da3e116b5f
7
- data.tar.gz: 0f9450b337d1c52c8b0f5ea0467d0c414a565be14d021f9a83678d35fdcad06e5561d4656b0f1220aea9403df276c04d5c3ac894d366d03c9744669f50fcc88e
6
+ metadata.gz: a51b76cd9d1903797d3dec529631c25ef8d1d3e326d3a73a86f76a1ac238902e679d9bda5809e701f9b5cad1a31b8f87ac6c5b54d957a2b78162fd4b184f5cf6
7
+ data.tar.gz: 95dc3cb99f04834cb29c86515e2ab8d6a0e1c73d572e23b28b043a060f3c98f356a8f57d7314451672483482ccbdd67195c85c253233b1488a004539ee3c67c9
@@ -0,0 +1,32 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ ruby: circleci/ruby@1.0
5
+
6
+ jobs:
7
+ build:
8
+ docker:
9
+ - image: cimg/ruby:2.5
10
+ steps:
11
+ - checkout
12
+ - ruby/install-deps
13
+ test:
14
+ parallelism: 3
15
+ docker:
16
+ - image: cimg/ruby:2.5
17
+ environment:
18
+ BUNDLE_JOBS: "3"
19
+ BUNDLE_RETRY: "3"
20
+ steps:
21
+ - checkout
22
+ - ruby/install-deps
23
+ - ruby/rspec-test
24
+
25
+ workflows:
26
+ version: 2
27
+ build_and_test:
28
+ jobs:
29
+ - build
30
+ - test:
31
+ requires:
32
+ - build
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-3.0.2
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in coffee_table.gemspec
4
4
  gemspec
5
-
6
- gem "awesome_print"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coffee_table (0.2.11)
4
+ coffee_table (0.3.1)
5
5
  activesupport
6
6
  gzip
7
7
  redis
@@ -9,77 +9,86 @@ PATH
9
9
  sourcify
10
10
 
11
11
  GEM
12
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (5.1.4)
14
+ activesupport (6.1.3.1)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
- i18n (~> 0.7)
17
- minitest (~> 5.1)
18
- tzinfo (~> 1.1)
19
- awesome_print (1.1.0)
20
- colorize (0.5.8)
21
- concurrent-ruby (1.0.5)
22
- coveralls (0.6.7)
23
- colorize
24
- multi_json (~> 1.3)
25
- rest-client
26
- simplecov (>= 0.7)
27
- thor
28
- diff-lcs (1.2.4)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ concurrent-ruby (1.1.8)
21
+ coveralls (0.8.23)
22
+ json (>= 1.8, < 3)
23
+ simplecov (~> 0.16.1)
24
+ term-ansicolor (~> 1.3)
25
+ thor (>= 0.19.4, < 2.0)
26
+ tins (~> 1.6)
27
+ diff-lcs (1.3)
28
+ docile (1.3.2)
29
29
  file-tail (1.2.0)
30
30
  tins (~> 1.0)
31
31
  gzip (1.0)
32
- i18n (0.9.3)
32
+ i18n (1.8.10)
33
33
  concurrent-ruby (~> 1.0)
34
- mime-types (1.23)
35
- minitest (5.11.3)
36
- mock_redis (0.17.0)
37
- multi_json (1.7.8)
38
- redis (4.0.1)
39
- redis-namespace (1.6.0)
34
+ json (2.3.0)
35
+ minitest (5.14.4)
36
+ mock_redis (0.23.0)
37
+ redis (4.2.5)
38
+ redis-namespace (1.8.1)
40
39
  redis (>= 3.0.4)
41
- rest-client (1.6.7)
42
- mime-types (>= 1.16)
43
- rspec (2.14.1)
44
- rspec-core (~> 2.14.0)
45
- rspec-expectations (~> 2.14.0)
46
- rspec-mocks (~> 2.14.0)
47
- rspec-core (2.14.4)
48
- rspec-expectations (2.14.1)
49
- diff-lcs (>= 1.1.3, < 2.0)
50
- rspec-mocks (2.14.3)
51
- ruby2ruby (2.4.0)
40
+ rspec (3.9.0)
41
+ rspec-core (~> 3.9.0)
42
+ rspec-expectations (~> 3.9.0)
43
+ rspec-mocks (~> 3.9.0)
44
+ rspec-core (3.9.2)
45
+ rspec-support (~> 3.9.3)
46
+ rspec-expectations (3.9.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-mocks (3.9.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.9.0)
52
+ rspec-support (3.9.3)
53
+ rspec_junit_formatter (0.4.1)
54
+ rspec-core (>= 2, < 4, != 2.12.0)
55
+ ruby2ruby (2.4.4)
52
56
  ruby_parser (~> 3.1)
53
57
  sexp_processor (~> 4.6)
54
- ruby_parser (3.10.1)
58
+ ruby_parser (3.15.1)
55
59
  sexp_processor (~> 4.9)
56
- sexp_processor (4.10.0)
57
- simplecov (0.7.1)
58
- multi_json (~> 1.0)
59
- simplecov-html (~> 0.7.1)
60
- simplecov-html (0.7.1)
60
+ sexp_processor (4.15.2)
61
+ simplecov (0.16.1)
62
+ docile (~> 1.1)
63
+ json (>= 1.8, < 3)
64
+ simplecov-html (~> 0.10.0)
65
+ simplecov-html (0.10.2)
61
66
  sourcify (0.5.0)
62
67
  file-tail (>= 1.0.5)
63
68
  ruby2ruby (>= 1.2.5)
64
69
  ruby_parser (>= 2.0.5)
65
70
  sexp_processor (>= 3.0.5)
66
71
  spork (0.9.2)
67
- thor (0.18.1)
68
- thread_safe (0.3.6)
69
- tins (1.16.3)
70
- tzinfo (1.2.4)
71
- thread_safe (~> 0.1)
72
+ sync (0.5.0)
73
+ term-ansicolor (1.7.1)
74
+ tins (~> 1.0)
75
+ thor (1.0.1)
76
+ tins (1.25.0)
77
+ sync
78
+ tzinfo (2.0.4)
79
+ concurrent-ruby (~> 1.0)
80
+ zeitwerk (2.4.2)
72
81
 
73
82
  PLATFORMS
74
83
  ruby
75
84
 
76
85
  DEPENDENCIES
77
- awesome_print
78
86
  coffee_table!
79
87
  coveralls
80
88
  mock_redis
81
89
  rspec
90
+ rspec_junit_formatter
82
91
  spork
83
92
 
84
93
  BUNDLED WITH
85
- 1.16.1
94
+ 2.1.4
data/README.textile CHANGED
@@ -2,7 +2,6 @@
2
2
  h1. CoffeeTable v0.2.8
3
3
 
4
4
  !https://badge.fury.io/rb/coffee_table.png!:http://badge.fury.io/rb/coffee_table
5
- !https://gemnasium.com/stewartmckee/coffee_table.png!
6
5
  !https://coveralls.io/repos/stewartmckee/coffee_table/badge.png?branch=master(Coverage Status)!:https://coveralls.io/r/stewartmckee/coffee_table
7
6
 
8
7
  h2. Intro
@@ -50,6 +49,8 @@ end
50
49
 
51
50
  Each time this is ran when a cache item doesn't exist, a unique cache key is generated based on the data passed in, and the code block being executed. It is good practice to put in objects that are used within the block, as in order to expire the key you need to specify the objects you want to expire for. If this key contained one of those objects, it would be removed and the next time this was ran, fresh data would be placed in the cache.
52
51
 
52
+ You can force to store a new cache entry by passing :force => true
53
+
53
54
  If you wish to specify a whole model type, for example, all users from above, you would pass in the class, for example:
54
55
 
55
56
  bc. user_details = @coffee_table.fetch(:user_detail, User) do
data/changelog.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.13
2
+ - removed awesome_print require
3
+
1
4
  0.2.12
2
5
  - fixing some specs
3
6
 
data/coffee_table.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency "mock_redis"
24
24
  s.add_development_dependency "spork"
25
25
  s.add_development_dependency "coveralls"
26
+ s.add_development_dependency "rspec_junit_formatter"
27
+
26
28
  s.add_dependency "redis"
27
29
  s.add_dependency "redis-namespace"
28
30
  s.add_dependency "activesupport"
@@ -6,15 +6,16 @@ module CoffeeTable
6
6
 
7
7
  def self.parse(string)
8
8
  elements = string.split("|", -1).map{|e| decode_element(e) }
9
- key = Key.new(elements[0], elements[1], Hash[elements.last.split("&").map{|kv| [kv.split("=")[0].to_sym, kv.split("=")[1]]}])
9
+ key = Key.new(name: elements[0], block_key: elements[1], flags: Hash[elements.last.split("&").map{|kv| [kv.split("=")[0].to_sym, kv.split("=")[1]]}])
10
10
  key.elements = elements[2..-2]
11
11
  key
12
12
  end
13
13
 
14
- def initialize(name, block_key, options, *objects)
15
- @name = name
16
- @block_key = block_key
17
- @options = options
14
+ def initialize(params = {}, *objects)
15
+ @block_key = params[:block_key] || ""
16
+ @flags = params[:flags] || {}
17
+ @options = params[:options] || {}
18
+ @name = "#{params[:name]}"
18
19
  @elements = objects.flatten.map{|o| key_for_object(o)}
19
20
  end
20
21
 
@@ -34,15 +35,15 @@ module CoffeeTable
34
35
  @block_key
35
36
  end
36
37
 
37
- def options
38
- @options
38
+ def flags
39
+ @flags
39
40
  end
40
41
 
41
- def add_flag(options)
42
- @options.merge!(options)
42
+ def add_flag(flags)
43
+ @flags.merge!(flags)
43
44
  end
44
45
  def remove_flag(key)
45
- @options.delete key
46
+ @flags.delete key
46
47
  end
47
48
 
48
49
  def elements
@@ -50,7 +51,7 @@ module CoffeeTable
50
51
  end
51
52
 
52
53
  def elements=(elements)
53
- @elements = elements
54
+ @elements = Array(elements)
54
55
  end
55
56
 
56
57
  def <=>(o)
@@ -58,16 +59,16 @@ module CoffeeTable
58
59
  end
59
60
 
60
61
  def to_s
61
- [encode_element(@name), encode_element(@block_key), @elements.map{|e| encode_element(e) }, encode_element(@options.map{|k,v| "#{k}=#{v}"}.join("&"))].flatten.join("|")
62
+ [encode_element(@name), encode_element(@block_key), @elements.map{|e| encode_element(e) }, encode_element(@flags.map{|k,v| "#{k}=#{v}"}.join("&"))].flatten.join("|")
62
63
  end
63
64
 
64
65
  private
65
66
 
66
- def matches?(fragment, options={})
67
- if options[:match] == :start
67
+ def matches?(fragment, flags={})
68
+ if flags[:match] == :start
68
69
  @name == fragment || !@elements.select{|e| e =~ /^#{Regexp.escape(fragment)}/ }.empty?
69
70
  else
70
- @name == fragment || @elements.include?(fragment)
71
+ @name == fragment || Array(@elements).include?(fragment)
71
72
  end
72
73
  end
73
74
 
@@ -1,3 +1,3 @@
1
1
  module CoffeeTable
2
- VERSION = "0.2.12"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/coffee_table.rb CHANGED
@@ -5,11 +5,10 @@ require "coffee_table/invalid_object_error"
5
5
  require "coffee_table/block_missing_error"
6
6
  require "coffee_table/object_definition"
7
7
  require "redis"
8
- require 'redis-namespace'
8
+ require "redis-namespace"
9
9
  require 'active_support/inflector'
10
10
  require 'digest/md5'
11
11
  require 'gzip'
12
- require 'awesome_print'
13
12
  require 'active_support/hash_with_indifferent_access'
14
13
 
15
14
  module CoffeeTable
@@ -17,6 +16,8 @@ module CoffeeTable
17
16
 
18
17
  include CoffeeTable::Utility
19
18
 
19
+ attr_reader :redis
20
+
20
21
  # initialize for coffee_table. takes options to setup behaviour of cache
21
22
  def initialize(options={})
22
23
  @options = options.symbolize_keys
@@ -40,6 +41,7 @@ module CoffeeTable
40
41
  end
41
42
 
42
43
  @redis = Redis::Namespace.new(@options[:redis_namespace], :redis => redis_client)
44
+ @real_redis = redis_client
43
45
 
44
46
  self
45
47
 
@@ -65,22 +67,21 @@ module CoffeeTable
65
67
  block_source = RubyVM::InstructionSequence.disasm(block.to_proc).to_s.gsub(/\(\s*\d+\)/, "").gsub(/^== disasm.*?$/, "")
66
68
  block_key = Digest::MD5.hexdigest(block_source)
67
69
  end
68
-
69
70
  flags = {}
70
71
 
71
72
  # if first related_object is integer or fixnum it is used as an expiry time for the cache object
72
- key = CoffeeTable::Key.new(initial_key, block_key, flags, related_objects)
73
+ key = CoffeeTable::Key.new({name: initial_key, block_key: block_key, options: @options, flags: flags}, related_objects)
73
74
  if @options[:enable_cache]
74
75
  if options.has_key?(:expiry)
75
76
  expiry = options[:expiry]
76
77
  else
77
78
  expiry = nil
78
79
  end
79
- if @redis.exists(key.to_s)
80
+ if keys.include?(key.to_s) && !options[:force]
80
81
  result = marshal_value(@redis.get(key.to_s))
81
82
  else
82
83
  key.add_flag(:compressed => true)
83
- if @redis.exists(key.to_s)
84
+ if keys.include?(key.to_s) && !options[:force]
84
85
  result = marshal_value(@redis.get(key.to_s)).gunzip
85
86
  else
86
87
  key.remove_flag(:compressed)
@@ -165,7 +166,11 @@ module CoffeeTable
165
166
 
166
167
  private
167
168
  def marshal_value(value)
169
+ return nil if value.nil?
168
170
  begin
171
+ # io = StringIO.new
172
+ # io.write(value)
173
+ # io.rewind
169
174
  result = Marshal.load(value)
170
175
  rescue ArgumentError => e
171
176
  puts "Attempting to load class/module #{e.message.split(" ")[-1]}"
@@ -6,12 +6,12 @@ describe CoffeeTable::Cache do
6
6
  @coffee_table = CoffeeTable::Cache.new
7
7
  end
8
8
 
9
- specify { CoffeeTable::Cache.should respond_to :new}
10
- specify { @coffee_table.should respond_to :fetch}
11
- specify { @coffee_table.should respond_to :expire_key}
12
- specify { @coffee_table.should respond_to :expire_all}
13
- specify { @coffee_table.should respond_to :keys}
14
- specify { @coffee_table.should respond_to :expire_for}
9
+ specify { expect(CoffeeTable::Cache).to respond_to :new}
10
+ specify { expect(@coffee_table).to respond_to :fetch}
11
+ specify { expect(@coffee_table).to respond_to :expire_key}
12
+ specify { expect(@coffee_table).to respond_to :expire_all}
13
+ specify { expect(@coffee_table).to respond_to :keys}
14
+ specify { expect(@coffee_table).to respond_to :expire_for}
15
15
 
16
16
  describe "config" do
17
17
  it "should take a hash for config" do
@@ -31,7 +31,7 @@ describe CoffeeTable::Cache do
31
31
  "this is a value"
32
32
  end
33
33
 
34
- result.should == "this is a value"
34
+ expect(result).to eq "this is a value"
35
35
  end
36
36
  it "should return cached value when cache available" do
37
37
  value = "this is a value"
@@ -43,7 +43,7 @@ describe CoffeeTable::Cache do
43
43
  value
44
44
  end
45
45
 
46
- result.should == "this is a value"
46
+ expect(result).to eq "this is a value"
47
47
 
48
48
  end
49
49
 
@@ -59,16 +59,17 @@ describe CoffeeTable::Cache do
59
59
  result = @coffee_table.fetch(:test_key) do
60
60
  "this string should be long"
61
61
  end
62
- result.should eql "this string should be long"
63
- @redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|compressed=true").should eq Marshal.dump(zipped_content)
62
+ expect(result).to eql "this string should be long"
63
+ puts "asdf"
64
+ @redis.get("test_key|009e2965832e67d06fb9a1b667cc1aca|compressed=true").should start_with "\u0004"
64
65
  end
65
66
  it "does not compress on non strings" do
66
67
  @coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
67
68
  result = @coffee_table.fetch(:test_key) do
68
69
  {:test => "this value is a decent length to trigger compress"}
69
70
  end
70
- result.should eql ({:test => "this value is a decent length to trigger compress"})
71
- Base64.encode64(@redis.get("test_key|6edc6a13bfb5a9f926072f34d1006557|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
71
+ expect(result).to eql ({:test => "this value is a decent length to trigger compress"})
72
+ Base64.encode64(@redis.get("test_key|8c3fde43e56b71d90843b9555673e120|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
72
73
  end
73
74
 
74
75
  it "does not compress when turned off" do
@@ -76,16 +77,16 @@ describe CoffeeTable::Cache do
76
77
  result = @coffee_table.fetch(:test_key) do
77
78
  "this string should be long"
78
79
  end
79
- result.should eql "this string should be long"
80
- @redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|").should eql Marshal.dump("this string should be long")
80
+ expect(result).to eql "this string should be long"
81
+ @redis.get("test_key|009e2965832e67d06fb9a1b667cc1aca|").should eql Marshal.dump("this string should be long")
81
82
  end
82
83
  it "does not compress on strings below limit" do
83
84
  @coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
84
85
  result = @coffee_table.fetch(:test_key) do
85
86
  "short"
86
87
  end
87
- result.should eql "short"
88
- @redis.get("test_key|f0b9a08ff52e14e59daa03aae70a5cab|").should eql Marshal.dump("short")
88
+ expect(result).to eql "short"
89
+ @redis.get("test_key|a2e7e06547b31ddc5dff0eba32b64753|").should eql Marshal.dump("short")
89
90
  end
90
91
  it "decompresses compressed value" do
91
92
  @coffee_table = CoffeeTable::Cache.new(:redis => @redis, :compress_min_size => 20)
@@ -95,8 +96,8 @@ describe CoffeeTable::Cache do
95
96
  result = @coffee_table.fetch(:test_key) do
96
97
  "this string should be long"
97
98
  end
98
- result.class.should eql String
99
- result.should eql "this string should be long"
99
+ expect(result.class).to eql String
100
+ expect(result).to eql "this string should be long"
100
101
 
101
102
  end
102
103
  it "does not decompress a non compressed value" do
@@ -107,7 +108,7 @@ describe CoffeeTable::Cache do
107
108
  result = @coffee_table.fetch(:test_key) do
108
109
  "short"
109
110
  end
110
- result.should eql "short"
111
+ expect(result).to eql "short"
111
112
  end
112
113
 
113
114
 
@@ -121,7 +122,7 @@ describe CoffeeTable::Cache do
121
122
  result = @coffee_table.fetch(:test_key) do
122
123
  "this is a changed value"
123
124
  end
124
- @coffee_table.keys.should == ["test_key|#{md5}|"]
125
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|"]
125
126
  end
126
127
 
127
128
  it "should create key from class" do
@@ -131,7 +132,7 @@ describe CoffeeTable::Cache do
131
132
  result = @coffee_table.fetch(:test_key, SampleClass) do
132
133
  "this is a changed value"
133
134
  end
134
- @coffee_table.keys.should == ["test_key|#{md5}|sample_classes|"]
135
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_classes|"]
135
136
  end
136
137
 
137
138
  it "should use class name for keys" do
@@ -141,7 +142,7 @@ describe CoffeeTable::Cache do
141
142
  result = @coffee_table.fetch(:test_key, SampleClass.new(2)) do
142
143
  "this is a changed value"
143
144
  end
144
- @coffee_table.keys.should == ["test_key|#{md5}|sample_class[2]|"]
145
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_class[2]|"]
145
146
  end
146
147
 
147
148
  it "should use id from class in key" do
@@ -151,7 +152,7 @@ describe CoffeeTable::Cache do
151
152
  result = @coffee_table.fetch(:test_key, SampleClass.new(2)) do
152
153
  "this is a changed value"
153
154
  end
154
- @coffee_table.keys.should == ["test_key|#{md5}|sample_class[2]|"]
155
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_class[2]|"]
155
156
  end
156
157
 
157
158
  end
@@ -167,7 +168,7 @@ describe CoffeeTable::Cache do
167
168
  "this is a changed value"
168
169
  end
169
170
 
170
- @coffee_table.keys.should include "test_key|#{md5}|sample_class[9938]|"
171
+ expect(@coffee_table.keys).to include "test_key|#{md5}|sample_class[9938]|"
171
172
 
172
173
  end
173
174
  it "should raise an exception if a related object does not respond_to id" do
@@ -190,7 +191,7 @@ describe CoffeeTable::Cache do
190
191
  "this is a changed value"
191
192
  end
192
193
 
193
- @coffee_table.keys.should include "test_key|#{md5}|sample_classes|"
194
+ expect(@coffee_table.keys).to include "test_key|#{md5}|sample_classes|"
194
195
  end
195
196
 
196
197
  end
@@ -199,9 +200,9 @@ describe CoffeeTable::Cache do
199
200
  @coffee_table.fetch(:test_key, :expiry => 1) do
200
201
  "object1"
201
202
  end
202
- @coffee_table.keys.count.should == 1
203
+ expect(@coffee_table.keys.count).to eq 1
203
204
  sleep 1
204
- @coffee_table.keys.count.should == 0
205
+ expect(@coffee_table.keys.count).to eq 0
205
206
  end
206
207
  it "should not execute block during cache period" do
207
208
  value = 'this is a value'
@@ -212,8 +213,7 @@ describe CoffeeTable::Cache do
212
213
  result = @coffee_table.fetch("asdf") do
213
214
  value
214
215
  end
215
- result.should == "this is a value"
216
-
216
+ expect(result).to eq "this is a value"
217
217
  end
218
218
  it "should execute block and return value when cache has expired" do
219
219
  @coffee_table.fetch("asdf", :expiry => 1) do
@@ -223,7 +223,26 @@ describe CoffeeTable::Cache do
223
223
  result = @coffee_table.fetch("asdf") do
224
224
  "this is a changed value"
225
225
  end
226
- result.should == "this is a changed value"
226
+ expect(result).to eq "this is a changed value"
227
+ end
228
+ end
229
+ context "with force" do
230
+ it "keys should update when cache expires" do
231
+ @coffee_table.fetch(:test_key, :force => true) do
232
+ "object1"
233
+ end
234
+ expect(@coffee_table.keys.count).to eq 1
235
+ end
236
+ it "should not execute block during cache period" do
237
+ value = 'this is a value'
238
+ @coffee_table.fetch("asdf") do
239
+ value
240
+ end
241
+ value = 'this is a changed value'
242
+ result = @coffee_table.fetch("asdf", :force => true) do
243
+ value
244
+ end
245
+ expect(result).to eq "this is a changed value"
227
246
  end
228
247
  end
229
248
 
@@ -237,7 +256,7 @@ describe CoffeeTable::Cache do
237
256
  result = @coffee_table.get_cache(:test_key) do
238
257
  object
239
258
  end
240
- result.should == "object1"
259
+ expect(result).to eq "object1"
241
260
  end
242
261
  it "should change key with changed code" do
243
262
  @coffee_table.get_cache(:test_key) do
@@ -246,7 +265,7 @@ describe CoffeeTable::Cache do
246
265
  result = @coffee_table.get_cache(:test_key) do
247
266
  "object2"
248
267
  end
249
- result.should == "object2"
268
+ expect(result).to eq "object2"
250
269
  end
251
270
  end
252
271
  end
@@ -276,9 +295,9 @@ describe CoffeeTable::Cache do
276
295
  "object3"
277
296
  end
278
297
 
279
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
298
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
280
299
  @coffee_table.expire_key("second_key")
281
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "third_key|#{@proc_md53}|"].sort
300
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "third_key|#{@proc_md53}|"].sort
282
301
 
283
302
  end
284
303
  it "should not expire anything if no matches" do
@@ -302,9 +321,9 @@ describe CoffeeTable::Cache do
302
321
  "object3"
303
322
  end
304
323
 
305
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
324
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
306
325
  @coffee_table.expire_key("fourth_key")
307
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
326
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
308
327
 
309
328
  end
310
329
 
@@ -322,7 +341,7 @@ describe CoffeeTable::Cache do
322
341
  "object2"
323
342
  end
324
343
 
325
- result.should == "object2"
344
+ expect(result).to eq "object2"
326
345
  end
327
346
 
328
347
  it "should not invalidate block when block has not changed" do
@@ -336,7 +355,7 @@ describe CoffeeTable::Cache do
336
355
  object
337
356
  end
338
357
 
339
- result.should == "object1"
358
+ expect(result).to eq "object1"
340
359
  end
341
360
 
342
361
  it "should not be affected by whitespace only changes" do
@@ -347,12 +366,10 @@ describe CoffeeTable::Cache do
347
366
 
348
367
  object = "object2"
349
368
  result = @coffee_table.fetch(:test_key) do
350
-
351
369
  object
352
-
353
370
  end
354
371
 
355
- result.should == "object1"
372
+ expect(result).to eq "object1"
356
373
  end
357
374
 
358
375
  end
@@ -372,7 +389,7 @@ describe CoffeeTable::Cache do
372
389
  "object2"
373
390
  end
374
391
 
375
- result.should == "object1"
392
+ expect(result).to eq "object1"
376
393
  end
377
394
  end
378
395
  end
@@ -396,15 +413,15 @@ describe CoffeeTable::Cache do
396
413
  end
397
414
 
398
415
  it "should delete all keys" do
399
- @coffee_table.keys.count.should == 3
416
+ expect(@coffee_table.keys.count).to eq 3
400
417
  @coffee_table.expire_all
401
- @coffee_table.keys.count.should == 0
418
+ expect(@coffee_table.keys.count).to eq 0
402
419
 
403
420
  result = @coffee_table.fetch(:first_key) do
404
421
  "changed value"
405
422
  end
406
423
 
407
- result.should == "changed value"
424
+ expect(result).to eq "changed value"
408
425
 
409
426
  end
410
427
  end
@@ -428,8 +445,8 @@ describe CoffeeTable::Cache do
428
445
  end
429
446
 
430
447
  it "should return an array of string" do
431
- @coffee_table.keys.should be_an_instance_of Array
432
- @coffee_table.keys.map{|key| key.should be_an_instance_of String}
448
+ expect(@coffee_table.keys).to be_an_instance_of Array
449
+ @coffee_table.keys.map{|key| expect(key).to be_an_instance_of String}
433
450
  end
434
451
  it "should return key created without objects" do
435
452
  @coffee_table.fetch(:first_key) do
@@ -442,7 +459,7 @@ describe CoffeeTable::Cache do
442
459
  "object3"
443
460
  end
444
461
 
445
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|",
462
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|",
446
463
  "second_key|#{@proc_md52}|",
447
464
  "third_key|#{@proc_md53}|"].sort
448
465
 
@@ -457,7 +474,7 @@ describe CoffeeTable::Cache do
457
474
  @coffee_table.fetch(:third_key, @object3) do
458
475
  "object3"
459
476
  end
460
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|sample_class[1]|sample_class[2]|sample_class[3]|",
477
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|sample_class[1]|sample_class[2]|sample_class[3]|",
461
478
  "second_key|#{@proc_md52}|sample_class[4]|sample_class[2]|sample_class[5]|",
462
479
  "third_key|#{@proc_md53}|sample_class[7]|sample_class[2]|sample_class[8]|"].sort
463
480
  end
@@ -482,47 +499,47 @@ describe CoffeeTable::Cache do
482
499
  end
483
500
 
484
501
  it "should expire based on the initial key" do
485
- @coffee_table.keys.count.should == 3
502
+ expect(@coffee_table.keys.count).to eq 3
486
503
  @coffee_table.expire_for(:second_key)
487
- @coffee_table.keys.count.should == 2
504
+ expect(@coffee_table.keys.count).to eq 2
488
505
  end
489
506
 
490
507
  it "should expire based on a simple string" do
491
- @coffee_table.keys.count.should == 3
508
+ expect(@coffee_table.keys.count).to eq 3
492
509
  @coffee_table.expire_for("sample_class[4]")
493
- @coffee_table.keys.count.should == 2
510
+ expect(@coffee_table.keys.count).to eq 2
494
511
  end
495
512
 
496
513
  it "should not expire based on a part match" do
497
- @coffee_table.keys.count.should == 3
514
+ expect(@coffee_table.keys.count).to eq 3
498
515
  @coffee_table.expire_for("impl")
499
- @coffee_table.keys.count.should == 3
516
+ expect(@coffee_table.keys.count).to eq 3
500
517
  end
501
518
 
502
519
  it "should not delete any keys if object is not present" do
503
- @coffee_table.keys.count.should == 3
520
+ expect(@coffee_table.keys.count).to eq 3
504
521
  @coffee_table.expire_for(SampleClass.new(18))
505
- @coffee_table.keys.count.should == 3
522
+ expect(@coffee_table.keys.count).to eq 3
506
523
  end
507
524
  it "should only delete keys that object is present in" do
508
- @coffee_table.keys.count.should == 3
525
+ expect(@coffee_table.keys.count).to eq 3
509
526
  @coffee_table.expire_for(SampleClass.new(1))
510
- @coffee_table.keys.count.should == 2
527
+ expect(@coffee_table.keys.count).to eq 2
511
528
  end
512
529
 
513
530
  it "should delete a key if the object is at the end of they key" do
514
- @coffee_table.keys.count.should == 3
531
+ expect(@coffee_table.keys.count).to eq 3
515
532
  @coffee_table.expire_for(SampleClass.new(3))
516
- @coffee_table.keys.count.should == 2
533
+ expect(@coffee_table.keys.count).to eq 2
517
534
  end
518
535
 
519
536
  it "should expire all keys relating to a class if uninitialised class is passed in" do
520
537
  @coffee_table.fetch(:fourth_key) do
521
538
  "object4"
522
539
  end
523
- @coffee_table.keys.count.should == 4
540
+ expect(@coffee_table.keys.count).to eq 4
524
541
  @coffee_table.expire_for(SampleClass)
525
- @coffee_table.keys.count.should == 1
542
+ expect(@coffee_table.keys.count).to eq 1
526
543
  end
527
544
  end
528
545
 
data/spec/lib/key_spec.rb CHANGED
@@ -4,13 +4,13 @@ describe CoffeeTable::Key do
4
4
 
5
5
  context "has correct methods" do
6
6
  it "should have a parse class method" do
7
- CoffeeTable::Key.should respond_to :parse
7
+ expect(CoffeeTable::Key).to respond_to :parse
8
8
  end
9
9
  it "should have a has_element? instance method" do
10
- CoffeeTable::Key.new("name", "key", {}).should respond_to :has_element?
10
+ expect(CoffeeTable::Key.new(name: "name", block_key: "key")).to respond_to :has_element?
11
11
  end
12
12
  it "should have a has_element_type? instance method" do
13
- CoffeeTable::Key.new("name", "key", {}).should respond_to :has_element_type?
13
+ expect(CoffeeTable::Key.new(name: "name", block_key: "key")).to respond_to :has_element_type?
14
14
  end
15
15
  end
16
16
 
@@ -19,51 +19,51 @@ describe CoffeeTable::Key do
19
19
  key = CoffeeTable::Key.parse("test|asdf|sample_class|")
20
20
 
21
21
 
22
- key.elements.count.should == 1
23
- key.name.should == "test"
24
- key.code_hash.should == "asdf"
25
- key.elements[0].should == "sample_class"
22
+ expect(key.elements.count).to eq 1
23
+ expect(key.name).to eq "test"
24
+ expect(key.code_hash).to eq "asdf"
25
+ expect(key.elements[0]).to eq "sample_class"
26
26
 
27
27
  end
28
28
  it "should decode encoded elements" do
29
29
  key = CoffeeTable::Key.parse("te&#124;s&amp;t|asdf&#124;s&amp;|sample_&#124;s&amp;class|")
30
30
 
31
31
 
32
- key.elements.count.should == 1
33
- key.name.should == "te|s&t"
34
- key.code_hash.should == "asdf|s&"
35
- key.elements[0].should == "sample_|s&class"
32
+ expect(key.elements.count).to eq 1
33
+ expect(key.name).to eq "te|s&t"
34
+ expect(key.code_hash).to eq "asdf|s&"
35
+ expect(key.elements[0]).to eq "sample_|s&class"
36
36
  end
37
37
  it "should encode the key data" do
38
38
 
39
- key = CoffeeTable::Key.new("te|s&t", "asdf|s&", {}, "sample_|s&class")
39
+ key = CoffeeTable::Key.new({name: "te|s&t", block_key: "asdf|s&"}, "sample_|s&class")
40
40
 
41
- key.name.should == "te|s&t"
42
- key.code_hash.should == "asdf|s&"
43
- key.elements[0].should == "sample_|s&class"
41
+ expect(key.name).to eq "te|s&t"
42
+ expect(key.code_hash).to eq "asdf|s&"
43
+ expect(key.elements[0]).to eq "sample_|s&class"
44
44
 
45
- key.to_s.should == "te&#124;s&amp;t|asdf&#124;s&amp;|sample_&#124;s&amp;class|"
45
+ expect(key.to_s).to eq "te&#124;s&amp;t|asdf&#124;s&amp;|sample_&#124;s&amp;class|"
46
46
 
47
47
  end
48
48
  end
49
49
 
50
50
  context "matching keys" do
51
51
  it "should match a key on its name" do
52
- key = CoffeeTable::Key.new("name", "key", {}, "value", ["value1", "value2"])
53
- key.has_element?("name").should be_true
54
- key.has_element?("key").should be_false
52
+ key = CoffeeTable::Key.new({name: "name", block_key: "key"}, "value", ["value1", "value2"])
53
+ expect(key.has_element?("name")).to be_truthy
54
+ expect(key.has_element?("key")).to be_falsey
55
55
  end
56
56
  it "should match a key on its data" do
57
- key = CoffeeTable::Key.new("name", "key", {}, "value", ["value1", "value2"])
58
- key.has_element?("key").should be_false
59
- key.has_element?("value").should be_true
60
- key.has_element?("value1").should be_true
61
- key.has_element?("value2").should be_true
57
+ key = CoffeeTable::Key.new({name: "name", block_key: "key"}, "value", ["value1", "value2"])
58
+ expect(key.has_element?("key")).to be_falsey
59
+ expect(key.has_element?("value")).to be_truthy
60
+ expect(key.has_element?("value1")).to be_truthy
61
+ expect(key.has_element?("value2")).to be_truthy
62
62
  end
63
63
  it "should match a key on a class type" do
64
- key = CoffeeTable::Key.new("name", "key", {}, "sample_class[3]", ["value1", "value2"])
65
- key.has_element?("key").should be_false
66
- key.has_element_type?("sample_class").should be_true
64
+ key = CoffeeTable::Key.new({name: "name", block_key: "key"}, "sample_class[3]", ["value1", "value2"])
65
+ expect(key.has_element?("key")).to be_falsey
66
+ expect(key.has_element_type?("sample_class")).to be_truthy
67
67
  end
68
68
  end
69
69
 
@@ -76,39 +76,39 @@ describe CoffeeTable::Key do
76
76
  end
77
77
 
78
78
  it "should encode options into key" do
79
- key = CoffeeTable::Key.new("name", "key", {:option => "value", :option2 => "value2"})
80
- key.to_s.should eql "name|key|option=value&amp;option2=value2"
79
+ key = CoffeeTable::Key.new(name: "name", block_key: "key", flags: {:option => "value", :option2 => "value2"})
80
+ expect(key.to_s).to eql "name|key|option=value&amp;option2=value2"
81
81
  end
82
82
  it "should parse back options out of key" do
83
83
  key = CoffeeTable::Key.parse("name|block|key=value")
84
- key.options.should eql ({:key => "value"})
84
+ expect(key.flags).to eql ({:key => "value"})
85
85
 
86
86
  end
87
87
  it "should handle no options" do
88
- key = CoffeeTable::Key.new("name", "key", {})
89
- key.to_s.should eql "name|key|"
88
+ key = CoffeeTable::Key.new(name: "name", block_key: "key")
89
+ expect(key.to_s).to eql "name|key|"
90
90
  end
91
91
 
92
92
  it "should handle one option" do
93
- key = CoffeeTable::Key.new("name", "key", {:option => "value"})
94
- key.to_s.should eql "name|key|option=value"
93
+ key = CoffeeTable::Key.new(name: "name", block_key: "key", flags: {:option => "value"})
94
+ expect(key.to_s).to eql "name|key|option=value"
95
95
  end
96
96
  it "should handle multiple options" do
97
- key = CoffeeTable::Key.new("name", "key", {:option => "value", :option2 => "value2"})
98
- key.to_s.should eql "name|key|option=value&amp;option2=value2"
97
+ key = CoffeeTable::Key.new(name: "name", block_key: "key", flags: {:option => "value", :option2 => "value2"})
98
+ expect(key.to_s).to eql "name|key|option=value&amp;option2=value2"
99
99
  end
100
100
 
101
101
  it "matches regardless of flags" do
102
- key = CoffeeTable::Key.new("name", "key", {:option => "value", :option2 => "value2"}, @obj1, @obj2, @obj3)
103
- key.has_element?("test[1]").should be_true
104
- key.has_element?("test[2]").should be_true
105
- key.has_element?("test[3]").should be_true
106
- key.has_element?("test[4]").should be_false
102
+ key = CoffeeTable::Key.new({name: "name", block_key: "key", flgas: {:option => "value", :option2 => "value2"}}, @obj1, @obj2, @obj3)
103
+ expect(key.has_element?("test[1]")).to be_truthy
104
+ expect(key.has_element?("test[2]")).to be_truthy
105
+ expect(key.has_element?("test[3]")).to be_truthy
106
+ expect(key.has_element?("test[4]")).to be_falsey
107
107
  end
108
108
 
109
109
  it "does not match on flag values" do
110
- key = CoffeeTable::Key.new("name", "key", {:option => "value", :option2 => "value2"}, @obj1, @obj2, @obj3)
111
- key.has_element?("option=value&amp;option2=value2").should be_false
110
+ key = CoffeeTable::Key.new({name: "name", block_key: "key", flags: {:option => "value", :option2 => "value2"}}, @obj1, @obj2, @obj3)
111
+ expect(key.has_element?("option=value&amp;option2=value2")).to be_falsey
112
112
 
113
113
  end
114
114
 
data/spec/spec_helper.rb CHANGED
@@ -7,29 +7,28 @@ Coveralls.wear!
7
7
  require 'digest/md5'
8
8
  require 'spork'
9
9
  # require 'mock_redis'
10
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/spec/lib/sample_class')
11
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/spec/lib/sample_class_without_id')
10
+ require File.expand_path(File.dirname(__FILE__) + '/../spec/lib/sample_class.rb')
11
+ require File.expand_path(File.dirname(__FILE__) + '/../spec/lib/sample_class_without_id.rb')
12
12
 
13
13
 
14
14
  Spork.prefork do
15
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/lib/coffee_table.rb')
16
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/lib/coffee_table/block_missing_error.rb')
17
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/lib/coffee_table/invalid_object_error.rb')
18
- require File.expand_path(File.dirname(__FILE__) + '/../../coffee_table/lib/coffee_table/key.rb')
15
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/coffee_table.rb')
16
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/coffee_table/block_missing_error.rb')
17
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/coffee_table/invalid_object_error.rb')
18
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/coffee_table/key.rb')
19
19
  end
20
20
 
21
21
  Spork.each_run do
22
22
  RSpec.configure do |config|
23
23
  config.before(:each) {
24
24
 
25
-
26
- # redis = double(:redis)
27
- # Redis.stub(:new).and_return(MockRedis.new)
28
- CoffeeTable::Cache.new.expire_all
25
+ redis = CoffeeTable::Cache.new.redis
26
+ redis.keys.map{|k| redis.del k }
29
27
 
30
28
  }
31
29
 
32
30
  config.after(:each) {
31
+ # CoffeeTable::Cache.new.expire_all
33
32
  }
34
33
  end
35
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stewart McKee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2022-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
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
  - !ruby/object:Gem::Dependency
70
84
  name: redis
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +157,7 @@ executables: []
143
157
  extensions: []
144
158
  extra_rdoc_files: []
145
159
  files:
160
+ - ".circleci/config.yml"
146
161
  - ".gitignore"
147
162
  - ".rspec"
148
163
  - ".ruby-gemset"
@@ -169,7 +184,7 @@ files:
169
184
  homepage: ''
170
185
  licenses: []
171
186
  metadata: {}
172
- post_install_message:
187
+ post_install_message:
173
188
  rdoc_options: []
174
189
  require_paths:
175
190
  - lib
@@ -184,9 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
199
  - !ruby/object:Gem::Version
185
200
  version: '0'
186
201
  requirements: []
187
- rubyforge_project: coffee_table
188
- rubygems_version: 2.6.12
189
- signing_key:
202
+ rubygems_version: 3.2.22
203
+ signing_key:
190
204
  specification_version: 4
191
205
  summary: Gem to manage cache stored in redis
192
206
  test_files: