coffee_table 0.2.9 → 0.3.0

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
- SHA1:
3
- metadata.gz: 76440727726d50fa105f8179d61ea8e9ff343155
4
- data.tar.gz: 9725cfa0cd6d258c97fb7ab367b76d004e5afab4
2
+ SHA256:
3
+ metadata.gz: 8331d649faef4d9b5ba700f8ac93cad2a263bd293e5535c721ed57a170140c7f
4
+ data.tar.gz: a26ffaba10d13a680e611aa39ba5d3b217acb4c786269b7435d05a354e4ae00c
5
5
  SHA512:
6
- metadata.gz: 66bd2063d488daff7a2ec7d1509cd9d783be47b12a9a53a23eac27d8ba2e4c6b9a3a86af367a1f0800cf823543745720a0974e56bbe344599bada82849aac1ca
7
- data.tar.gz: 0defff99f03e2ac25a732cd1a00bce539936384efdecdb292d5e344bdcef8366bb4d93da17cdbb6711467b95da03c28c82b93495603127d7666957279c18d69a
6
+ metadata.gz: c4a5cfdda959a00ea4e79bc41b296771f2eb44cb0dbae1db5f1daf638a6995b7f19b1f678cdfa64139424cd9cf639e92130dbfc1e8fb35f38f5cf2f31331861b
7
+ data.tar.gz: 9228a6f6c205dfaca58386cf08777818a8e57ceb48726dcb705625dec76cabcb3aa9d2da43bd7645bd6cb06b7782e24c484432bb1a550033c165e028afb44276
@@ -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
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-2.5.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coffee_table (0.2.8)
4
+ coffee_table (0.3.0)
5
5
  activesupport
6
6
  gzip
7
7
  redis
@@ -11,74 +11,85 @@ PATH
11
11
  GEM
12
12
  remote: http://rubygems.org/
13
13
  specs:
14
- activesupport (5.1.4)
14
+ activesupport (6.0.3.1)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
- i18n (~> 0.7)
16
+ i18n (>= 0.7, < 2)
17
17
  minitest (~> 5.1)
18
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)
19
+ zeitwerk (~> 2.2, >= 2.2.2)
20
+ concurrent-ruby (1.1.6)
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.8.6)
33
- mime-types (1.23)
34
- minitest (5.10.3)
35
- mock_redis (0.17.0)
36
- multi_json (1.7.8)
37
- redis (3.3.3)
38
- redis-namespace (1.5.3)
39
- redis (~> 3.0, >= 3.0.4)
40
- rest-client (1.6.7)
41
- mime-types (>= 1.16)
42
- rspec (2.14.1)
43
- rspec-core (~> 2.14.0)
44
- rspec-expectations (~> 2.14.0)
45
- rspec-mocks (~> 2.14.0)
46
- rspec-core (2.14.4)
47
- rspec-expectations (2.14.1)
48
- diff-lcs (>= 1.1.3, < 2.0)
49
- rspec-mocks (2.14.3)
50
- ruby2ruby (2.4.0)
32
+ i18n (1.8.3)
33
+ concurrent-ruby (~> 1.0)
34
+ json (2.3.0)
35
+ minitest (5.14.1)
36
+ mock_redis (0.23.0)
37
+ redis (4.2.1)
38
+ redis-namespace (1.7.0)
39
+ redis (>= 3.0.4)
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)
51
56
  ruby_parser (~> 3.1)
52
57
  sexp_processor (~> 4.6)
53
- ruby_parser (3.10.1)
58
+ ruby_parser (3.14.2)
54
59
  sexp_processor (~> 4.9)
55
- sexp_processor (4.10.0)
56
- simplecov (0.7.1)
57
- multi_json (~> 1.0)
58
- simplecov-html (~> 0.7.1)
59
- simplecov-html (0.7.1)
60
+ sexp_processor (4.15.0)
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)
60
66
  sourcify (0.5.0)
61
67
  file-tail (>= 1.0.5)
62
68
  ruby2ruby (>= 1.2.5)
63
69
  ruby_parser (>= 2.0.5)
64
70
  sexp_processor (>= 3.0.5)
65
71
  spork (0.9.2)
66
- thor (0.18.1)
72
+ sync (0.5.0)
73
+ term-ansicolor (1.7.1)
74
+ tins (~> 1.0)
75
+ thor (1.0.1)
67
76
  thread_safe (0.3.6)
68
- tins (1.15.0)
69
- tzinfo (1.2.3)
77
+ tins (1.25.0)
78
+ sync
79
+ tzinfo (1.2.7)
70
80
  thread_safe (~> 0.1)
81
+ zeitwerk (2.3.0)
71
82
 
72
83
  PLATFORMS
73
84
  ruby
74
85
 
75
86
  DEPENDENCIES
76
- awesome_print
77
87
  coffee_table!
78
88
  coveralls
79
89
  mock_redis
80
90
  rspec
91
+ rspec_junit_formatter
81
92
  spork
82
93
 
83
94
  BUNDLED WITH
84
- 1.15.4
95
+ 2.1.4
@@ -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
@@ -1,3 +1,15 @@
1
+ 0.2.13
2
+ - removed awesome_print require
3
+
4
+ 0.2.12
5
+ - fixing some specs
6
+
7
+ 0.2.11
8
+ - removed awesome_print require
9
+
10
+ 0.2.10
11
+ - fixed bug in setting up redis
12
+
1
13
  0.2.8
2
14
  - removed rufus-scheduler
3
15
 
@@ -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"
@@ -5,19 +5,22 @@ 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 'active_support/hash_with_indifferent_access'
12
13
 
13
14
  module CoffeeTable
14
15
  class Cache
15
16
 
16
17
  include CoffeeTable::Utility
17
18
 
19
+ attr_reader :redis
20
+
18
21
  # initialize for coffee_table. takes options to setup behaviour of cache
19
22
  def initialize(options={})
20
- @options = options
23
+ @options = options.symbolize_keys
21
24
 
22
25
  default_enable_cache_to true
23
26
  default_redis_namespace_to :coffee_table
@@ -28,13 +31,20 @@ module CoffeeTable
28
31
  default_compress_content_to true
29
32
  default_compress_min_size_to 10240
30
33
 
34
+ redis_client = nil
31
35
  if !@options[:redis].nil?
32
- @redis = Redis::Namespace.new(@options[:redis_namespace], :redis => @options[:redis])
36
+ redis_client = @options[:redis]
33
37
  elsif @options.has_key?(:redis_url)
34
- @redis = Redis::Namespace.new(@options[:redis_namespace], {:url => @options[:redis_url]})
38
+ redis_client = Redis.new(:url => @options[:redis_url])
35
39
  else
36
- @redis = Redis::Namespace.new(@options[:redis_namespace], {:server => @options[:redis_server], :port => @options[:redis_port]})
40
+ redis_client = Redis.new(:host => @options[:redis_server], :port => @options[:redis_port])
37
41
  end
42
+
43
+ @redis = Redis::Namespace.new(@options[:redis_namespace], :redis => redis_client)
44
+ @real_redis = redis_client
45
+
46
+ self
47
+
38
48
  end
39
49
 
40
50
 
@@ -57,22 +67,21 @@ module CoffeeTable
57
67
  block_source = RubyVM::InstructionSequence.disasm(block.to_proc).to_s.gsub(/\(\s*\d+\)/, "").gsub(/^== disasm.*?$/, "")
58
68
  block_key = Digest::MD5.hexdigest(block_source)
59
69
  end
60
-
61
70
  flags = {}
62
71
 
63
72
  # if first related_object is integer or fixnum it is used as an expiry time for the cache object
64
- 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)
65
74
  if @options[:enable_cache]
66
75
  if options.has_key?(:expiry)
67
76
  expiry = options[:expiry]
68
77
  else
69
78
  expiry = nil
70
79
  end
71
- if @redis.exists(key.to_s)
80
+ if keys.include?(key.to_s)
72
81
  result = marshal_value(@redis.get(key.to_s))
73
82
  else
74
83
  key.add_flag(:compressed => true)
75
- if @redis.exists(key.to_s)
84
+ if keys.include?(key.to_s)
76
85
  result = marshal_value(@redis.get(key.to_s)).gunzip
77
86
  else
78
87
  key.remove_flag(:compressed)
@@ -157,7 +166,11 @@ module CoffeeTable
157
166
 
158
167
  private
159
168
  def marshal_value(value)
169
+ return nil if value.nil?
160
170
  begin
171
+ # io = StringIO.new
172
+ # io.write(value)
173
+ # io.rewind
161
174
  result = Marshal.load(value)
162
175
  rescue ArgumentError => e
163
176
  puts "Attempting to load class/module #{e.message.split(" ")[-1]}"
@@ -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.9"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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,15 +43,14 @@ 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
 
50
50
  context "compressing" do
51
51
 
52
52
  before(:each) do
53
- @redis = Redis::Namespace.new("coffee_table", {:server => "127.0.0.1", :port => 6379})
54
-
53
+ @redis = Redis::Namespace.new("coffee_table", :redis => Redis.new)
55
54
  end
56
55
 
57
56
  it "compresses on strings greater than limit" do
@@ -60,16 +59,16 @@ describe CoffeeTable::Cache do
60
59
  result = @coffee_table.fetch(:test_key) do
61
60
  "this string should be long"
62
61
  end
63
- result.should eql "this string should be long"
64
- @redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|compressed=true").should eq Marshal.dump(zipped_content)
62
+ expect(result).to eql "this string should be long"
63
+ @redis.get("test_key|90a52c9dc8646bf66e93ce76578306c6|compressed=true").should start_with "\u0004"
65
64
  end
66
65
  it "does not compress on non strings" do
67
66
  @coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
68
67
  result = @coffee_table.fetch(:test_key) do
69
68
  {:test => "this value is a decent length to trigger compress"}
70
69
  end
71
- result.should eql ({:test => "this value is a decent length to trigger compress"})
72
- Base64.encode64(@redis.get("test_key|6edc6a13bfb5a9f926072f34d1006557|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
70
+ expect(result).to eql ({:test => "this value is a decent length to trigger compress"})
71
+ Base64.encode64(@redis.get("test_key|0402899032596ee850d5271ab2312906|")).should eql "BAh7BjoJdGVzdEkiNnRoaXMgdmFsdWUgaXMgYSBkZWNlbnQgbGVuZ3RoIHRv\nIHRyaWdnZXIgY29tcHJlc3MGOgZFVA==\n"
73
72
  end
74
73
 
75
74
  it "does not compress when turned off" do
@@ -77,16 +76,16 @@ describe CoffeeTable::Cache do
77
76
  result = @coffee_table.fetch(:test_key) do
78
77
  "this string should be long"
79
78
  end
80
- result.should eql "this string should be long"
81
- @redis.get("test_key|1c083b7ed4b406f263ef329a608a80b9|").should eql Marshal.dump("this string should be long")
79
+ expect(result).to eql "this string should be long"
80
+ @redis.get("test_key|90a52c9dc8646bf66e93ce76578306c6|").should eql Marshal.dump("this string should be long")
82
81
  end
83
82
  it "does not compress on strings below limit" do
84
83
  @coffee_table = CoffeeTable::Cache.new(:server => "127.0.0.1", :port => 6379, :compress_min_size => 20)
85
84
  result = @coffee_table.fetch(:test_key) do
86
85
  "short"
87
86
  end
88
- result.should eql "short"
89
- @redis.get("test_key|f0b9a08ff52e14e59daa03aae70a5cab|").should eql Marshal.dump("short")
87
+ expect(result).to eql "short"
88
+ @redis.get("test_key|55d2ae66967c26b2fef23e5ed6bd3930|").should eql Marshal.dump("short")
90
89
  end
91
90
  it "decompresses compressed value" do
92
91
  @coffee_table = CoffeeTable::Cache.new(:redis => @redis, :compress_min_size => 20)
@@ -96,8 +95,8 @@ describe CoffeeTable::Cache do
96
95
  result = @coffee_table.fetch(:test_key) do
97
96
  "this string should be long"
98
97
  end
99
- result.class.should eql String
100
- result.should eql "this string should be long"
98
+ expect(result.class).to eql String
99
+ expect(result).to eql "this string should be long"
101
100
 
102
101
  end
103
102
  it "does not decompress a non compressed value" do
@@ -108,7 +107,7 @@ describe CoffeeTable::Cache do
108
107
  result = @coffee_table.fetch(:test_key) do
109
108
  "short"
110
109
  end
111
- result.should eql "short"
110
+ expect(result).to eql "short"
112
111
  end
113
112
 
114
113
 
@@ -122,7 +121,7 @@ describe CoffeeTable::Cache do
122
121
  result = @coffee_table.fetch(:test_key) do
123
122
  "this is a changed value"
124
123
  end
125
- @coffee_table.keys.should == ["test_key|#{md5}|"]
124
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|"]
126
125
  end
127
126
 
128
127
  it "should create key from class" do
@@ -132,7 +131,7 @@ describe CoffeeTable::Cache do
132
131
  result = @coffee_table.fetch(:test_key, SampleClass) do
133
132
  "this is a changed value"
134
133
  end
135
- @coffee_table.keys.should == ["test_key|#{md5}|sample_classes|"]
134
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_classes|"]
136
135
  end
137
136
 
138
137
  it "should use class name for keys" do
@@ -142,7 +141,7 @@ describe CoffeeTable::Cache do
142
141
  result = @coffee_table.fetch(:test_key, SampleClass.new(2)) do
143
142
  "this is a changed value"
144
143
  end
145
- @coffee_table.keys.should == ["test_key|#{md5}|sample_class[2]|"]
144
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_class[2]|"]
146
145
  end
147
146
 
148
147
  it "should use id from class in key" do
@@ -152,7 +151,7 @@ describe CoffeeTable::Cache do
152
151
  result = @coffee_table.fetch(:test_key, SampleClass.new(2)) do
153
152
  "this is a changed value"
154
153
  end
155
- @coffee_table.keys.should == ["test_key|#{md5}|sample_class[2]|"]
154
+ expect(@coffee_table.keys).to eq ["test_key|#{md5}|sample_class[2]|"]
156
155
  end
157
156
 
158
157
  end
@@ -168,7 +167,7 @@ describe CoffeeTable::Cache do
168
167
  "this is a changed value"
169
168
  end
170
169
 
171
- @coffee_table.keys.should include "test_key|#{md5}|sample_class[9938]|"
170
+ expect(@coffee_table.keys).to include "test_key|#{md5}|sample_class[9938]|"
172
171
 
173
172
  end
174
173
  it "should raise an exception if a related object does not respond_to id" do
@@ -191,7 +190,7 @@ describe CoffeeTable::Cache do
191
190
  "this is a changed value"
192
191
  end
193
192
 
194
- @coffee_table.keys.should include "test_key|#{md5}|sample_classes|"
193
+ expect(@coffee_table.keys).to include "test_key|#{md5}|sample_classes|"
195
194
  end
196
195
 
197
196
  end
@@ -200,9 +199,9 @@ describe CoffeeTable::Cache do
200
199
  @coffee_table.fetch(:test_key, :expiry => 1) do
201
200
  "object1"
202
201
  end
203
- @coffee_table.keys.count.should == 1
202
+ expect(@coffee_table.keys.count).to eq 1
204
203
  sleep 1
205
- @coffee_table.keys.count.should == 0
204
+ expect(@coffee_table.keys.count).to eq 0
206
205
  end
207
206
  it "should not execute block during cache period" do
208
207
  value = 'this is a value'
@@ -213,8 +212,7 @@ describe CoffeeTable::Cache do
213
212
  result = @coffee_table.fetch("asdf") do
214
213
  value
215
214
  end
216
- result.should == "this is a value"
217
-
215
+ expect(result).to eq "this is a value"
218
216
  end
219
217
  it "should execute block and return value when cache has expired" do
220
218
  @coffee_table.fetch("asdf", :expiry => 1) do
@@ -224,7 +222,7 @@ describe CoffeeTable::Cache do
224
222
  result = @coffee_table.fetch("asdf") do
225
223
  "this is a changed value"
226
224
  end
227
- result.should == "this is a changed value"
225
+ expect(result).to eq "this is a changed value"
228
226
  end
229
227
  end
230
228
 
@@ -238,7 +236,7 @@ describe CoffeeTable::Cache do
238
236
  result = @coffee_table.get_cache(:test_key) do
239
237
  object
240
238
  end
241
- result.should == "object1"
239
+ expect(result).to eq "object1"
242
240
  end
243
241
  it "should change key with changed code" do
244
242
  @coffee_table.get_cache(:test_key) do
@@ -247,7 +245,7 @@ describe CoffeeTable::Cache do
247
245
  result = @coffee_table.get_cache(:test_key) do
248
246
  "object2"
249
247
  end
250
- result.should == "object2"
248
+ expect(result).to eq "object2"
251
249
  end
252
250
  end
253
251
  end
@@ -277,9 +275,9 @@ describe CoffeeTable::Cache do
277
275
  "object3"
278
276
  end
279
277
 
280
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
278
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
281
279
  @coffee_table.expire_key("second_key")
282
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "third_key|#{@proc_md53}|"].sort
280
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "third_key|#{@proc_md53}|"].sort
283
281
 
284
282
  end
285
283
  it "should not expire anything if no matches" do
@@ -303,9 +301,9 @@ describe CoffeeTable::Cache do
303
301
  "object3"
304
302
  end
305
303
 
306
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
304
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
307
305
  @coffee_table.expire_key("fourth_key")
308
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
306
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|", "second_key|#{@proc_md52}|", "third_key|#{@proc_md53}|"].sort
309
307
 
310
308
  end
311
309
 
@@ -323,7 +321,7 @@ describe CoffeeTable::Cache do
323
321
  "object2"
324
322
  end
325
323
 
326
- result.should == "object2"
324
+ expect(result).to eq "object2"
327
325
  end
328
326
 
329
327
  it "should not invalidate block when block has not changed" do
@@ -337,7 +335,7 @@ describe CoffeeTable::Cache do
337
335
  object
338
336
  end
339
337
 
340
- result.should == "object1"
338
+ expect(result).to eq "object1"
341
339
  end
342
340
 
343
341
  it "should not be affected by whitespace only changes" do
@@ -348,12 +346,10 @@ describe CoffeeTable::Cache do
348
346
 
349
347
  object = "object2"
350
348
  result = @coffee_table.fetch(:test_key) do
351
-
352
349
  object
353
-
354
350
  end
355
351
 
356
- result.should == "object1"
352
+ expect(result).to eq "object1"
357
353
  end
358
354
 
359
355
  end
@@ -373,7 +369,7 @@ describe CoffeeTable::Cache do
373
369
  "object2"
374
370
  end
375
371
 
376
- result.should == "object1"
372
+ expect(result).to eq "object1"
377
373
  end
378
374
  end
379
375
  end
@@ -397,15 +393,15 @@ describe CoffeeTable::Cache do
397
393
  end
398
394
 
399
395
  it "should delete all keys" do
400
- @coffee_table.keys.count.should == 3
396
+ expect(@coffee_table.keys.count).to eq 3
401
397
  @coffee_table.expire_all
402
- @coffee_table.keys.count.should == 0
398
+ expect(@coffee_table.keys.count).to eq 0
403
399
 
404
400
  result = @coffee_table.fetch(:first_key) do
405
401
  "changed value"
406
402
  end
407
403
 
408
- result.should == "changed value"
404
+ expect(result).to eq "changed value"
409
405
 
410
406
  end
411
407
  end
@@ -429,8 +425,8 @@ describe CoffeeTable::Cache do
429
425
  end
430
426
 
431
427
  it "should return an array of string" do
432
- @coffee_table.keys.should be_an_instance_of Array
433
- @coffee_table.keys.map{|key| key.should be_an_instance_of String}
428
+ expect(@coffee_table.keys).to be_an_instance_of Array
429
+ @coffee_table.keys.map{|key| expect(key).to be_an_instance_of String}
434
430
  end
435
431
  it "should return key created without objects" do
436
432
  @coffee_table.fetch(:first_key) do
@@ -443,7 +439,7 @@ describe CoffeeTable::Cache do
443
439
  "object3"
444
440
  end
445
441
 
446
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|",
442
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|",
447
443
  "second_key|#{@proc_md52}|",
448
444
  "third_key|#{@proc_md53}|"].sort
449
445
 
@@ -458,7 +454,7 @@ describe CoffeeTable::Cache do
458
454
  @coffee_table.fetch(:third_key, @object3) do
459
455
  "object3"
460
456
  end
461
- @coffee_table.keys.sort.should == ["first_key|#{@proc_md51}|sample_class[1]|sample_class[2]|sample_class[3]|",
457
+ expect(@coffee_table.keys.sort).to eq ["first_key|#{@proc_md51}|sample_class[1]|sample_class[2]|sample_class[3]|",
462
458
  "second_key|#{@proc_md52}|sample_class[4]|sample_class[2]|sample_class[5]|",
463
459
  "third_key|#{@proc_md53}|sample_class[7]|sample_class[2]|sample_class[8]|"].sort
464
460
  end
@@ -483,47 +479,47 @@ describe CoffeeTable::Cache do
483
479
  end
484
480
 
485
481
  it "should expire based on the initial key" do
486
- @coffee_table.keys.count.should == 3
482
+ expect(@coffee_table.keys.count).to eq 3
487
483
  @coffee_table.expire_for(:second_key)
488
- @coffee_table.keys.count.should == 2
484
+ expect(@coffee_table.keys.count).to eq 2
489
485
  end
490
486
 
491
487
  it "should expire based on a simple string" do
492
- @coffee_table.keys.count.should == 3
488
+ expect(@coffee_table.keys.count).to eq 3
493
489
  @coffee_table.expire_for("sample_class[4]")
494
- @coffee_table.keys.count.should == 2
490
+ expect(@coffee_table.keys.count).to eq 2
495
491
  end
496
492
 
497
493
  it "should not expire based on a part match" do
498
- @coffee_table.keys.count.should == 3
494
+ expect(@coffee_table.keys.count).to eq 3
499
495
  @coffee_table.expire_for("impl")
500
- @coffee_table.keys.count.should == 3
496
+ expect(@coffee_table.keys.count).to eq 3
501
497
  end
502
498
 
503
499
  it "should not delete any keys if object is not present" do
504
- @coffee_table.keys.count.should == 3
500
+ expect(@coffee_table.keys.count).to eq 3
505
501
  @coffee_table.expire_for(SampleClass.new(18))
506
- @coffee_table.keys.count.should == 3
502
+ expect(@coffee_table.keys.count).to eq 3
507
503
  end
508
504
  it "should only delete keys that object is present in" do
509
- @coffee_table.keys.count.should == 3
505
+ expect(@coffee_table.keys.count).to eq 3
510
506
  @coffee_table.expire_for(SampleClass.new(1))
511
- @coffee_table.keys.count.should == 2
507
+ expect(@coffee_table.keys.count).to eq 2
512
508
  end
513
509
 
514
510
  it "should delete a key if the object is at the end of they key" do
515
- @coffee_table.keys.count.should == 3
511
+ expect(@coffee_table.keys.count).to eq 3
516
512
  @coffee_table.expire_for(SampleClass.new(3))
517
- @coffee_table.keys.count.should == 2
513
+ expect(@coffee_table.keys.count).to eq 2
518
514
  end
519
515
 
520
516
  it "should expire all keys relating to a class if uninitialised class is passed in" do
521
517
  @coffee_table.fetch(:fourth_key) do
522
518
  "object4"
523
519
  end
524
- @coffee_table.keys.count.should == 4
520
+ expect(@coffee_table.keys.count).to eq 4
525
521
  @coffee_table.expire_for(SampleClass)
526
- @coffee_table.keys.count.should == 1
522
+ expect(@coffee_table.keys.count).to eq 1
527
523
  end
528
524
  end
529
525
 
@@ -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
 
@@ -6,30 +6,29 @@ Coveralls.wear!
6
6
 
7
7
  require 'digest/md5'
8
8
  require 'spork'
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')
9
+ # require 'mock_redis'
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.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stewart McKee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2020-06-12 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"
@@ -185,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
200
  version: '0'
186
201
  requirements: []
187
202
  rubyforge_project: coffee_table
188
- rubygems_version: 2.6.12
203
+ rubygems_version: 2.7.8
189
204
  signing_key:
190
205
  specification_version: 4
191
206
  summary: Gem to manage cache stored in redis