coffee_table 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5096de8fb62f3418eb4a02a02d460245b828ce4d
4
+ data.tar.gz: dee65858546fbc737b5340a821203dcc3309e0d6
5
+ SHA512:
6
+ metadata.gz: 36db338c9a66794aaf55b9ae72f2cb9d2d9a01aafd23919947fbde22d907ce2cc8a7fe84b0a555e509cf19ee9677a725916aea7358333946c7b417603e5c223e
7
+ data.tar.gz: 2ab2325828a57a1be2a1666fd03ae6fb8e79b1bbb00f33c219c91c506bcf21bee3fe6cbcd08167675eb9dcf26a452dff6ce1a2f6844f4beb2f5302b91ccf803e
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3-p392
1
+ ruby-2.3.0
data/Gemfile.lock CHANGED
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- coffee_table (0.1.2)
14
+ coffee_table (0.1.3)
15
15
  activesupport
16
16
  gzip
17
17
  redis
@@ -40,7 +40,7 @@ GEM
40
40
  mime-types (1.23)
41
41
  mock_redis (0.9.0)
42
42
  multi_json (1.7.8)
43
- redis (3.0.4)
43
+ redis (3.2.2)
44
44
  rest-client (1.6.7)
45
45
  mime-types (>= 1.16)
46
46
  rspec (2.14.1)
@@ -82,3 +82,6 @@ DEPENDENCIES
82
82
  rufus-scheduler
83
83
  sourcify!
84
84
  spork
85
+
86
+ BUNDLED WITH
87
+ 1.11.2
@@ -6,6 +6,10 @@ module CoffeeTable
6
6
  @id = id
7
7
  end
8
8
 
9
+ def id
10
+ @id
11
+ end
12
+
9
13
  def self.from_hash(hash)
10
14
  hash.map {|k, v| ObjectDefinition.new(k, v)}
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module CoffeeTable
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/coffee_table.rb CHANGED
@@ -7,7 +7,6 @@ require "coffee_table/object_definition"
7
7
  require "redis"
8
8
  require 'rufus/scheduler'
9
9
  require 'active_support/inflector'
10
- require 'sourcify'
11
10
  require 'digest/md5'
12
11
  require 'gzip'
13
12
 
@@ -29,11 +28,15 @@ module CoffeeTable
29
28
  default_compress_content_to true
30
29
  default_compress_min_size_to 10240
31
30
  @redis = Redis.new({:server => @options[:redis_server], :port => @options[:redis_port]})
32
- @scheduler = Rufus::Scheduler.start_new
33
-
31
+ rufus_version = Gem::Version.new(Rufus::Scheduler::VERSION)
32
+ if rufus_version >= Gem::Version.new('3.0.0')
33
+ @scheduler = Rufus::Scheduler.new
34
+ else
35
+ @scheduler = Rufus::Scheduler.start_new
36
+ end
34
37
  end
35
38
 
36
-
39
+
37
40
  def fetch(initial_key, *related_objects, &block)
38
41
  raise CoffeeTable::BlockMissingError, "No block given to generate cache from" unless block_given?
39
42
 
@@ -47,11 +50,11 @@ module CoffeeTable
47
50
  # check objects are valid
48
51
  related_objects.flatten.map{|o| raise CoffeeTable::InvalidObjectError, "Objects passed in must have an id method or be a class" unless object_valid?(o)}
49
52
 
50
- if @options[:ignore_code_changes]
53
+ # if @options[:ignore_code_changes]
51
54
  block_key = ""
52
- else
53
- block_key = Digest::MD5.hexdigest(block.to_source)
54
- end
55
+ # else
56
+ # block_key = Digest::MD5.hexdigest(block.to_source)
57
+ # end
55
58
 
56
59
  flags = {}
57
60
 
@@ -59,14 +62,14 @@ module CoffeeTable
59
62
 
60
63
  # if first related_object is integer or fixnum it is used as an expiry time for the cache object
61
64
  key = CoffeeTable::Key.new(initial_key, block_key, flags, related_objects)
62
-
65
+
63
66
  if @options[:enable_cache]
64
67
  if options.has_key?(:expiry)
65
68
  expiry = options[:expiry]
66
69
  else
67
70
  expiry = nil
68
71
  end
69
-
72
+
70
73
  @redis.sadd "cache_keys", key unless @redis.sismember "cache_keys", key.to_s
71
74
  if @redis.exists(key.to_s)
72
75
  if key.options[:compressed]
@@ -98,22 +101,22 @@ module CoffeeTable
98
101
  end
99
102
  result
100
103
  end
101
-
104
+
102
105
  def expire_key(key_value)
103
106
  keys.map{|k| CoffeeTable::Key.parse(k)}.select{|key| key.has_element?(key_value) || key.to_s == key_value }.each do |key|
104
107
  @redis.del(key.to_s)
105
108
  @redis.srem "cache_keys", key.to_s
106
109
  end
107
110
  end
108
-
111
+
109
112
  def expire_all
110
113
  keys.map{|key| expire_key(key)}
111
114
  end
112
-
115
+
113
116
  def keys
114
117
  @redis.smembers("cache_keys")
115
- end
116
-
118
+ end
119
+
117
120
  def expire_for(*objects)
118
121
  if defined? Rails
119
122
  perform_caching = Rails.application.configure do
@@ -122,7 +125,7 @@ module CoffeeTable
122
125
  else
123
126
  perform_caching = true
124
127
  end
125
-
128
+
126
129
  if perform_caching
127
130
  deleted_keys = []
128
131
  unless objects.count == 0
@@ -143,7 +146,7 @@ module CoffeeTable
143
146
  unless key.has_element?("#{object_type.to_sym}[#{object.id}]") or key.has_element?(object_type)
144
147
  expire = false
145
148
  end
146
- end
149
+ end
147
150
  end
148
151
  if expire
149
152
  expire_key(key.to_s)
@@ -156,7 +159,7 @@ module CoffeeTable
156
159
  end
157
160
 
158
161
  alias :get_cache :fetch
159
-
162
+
160
163
  private
161
164
  def marshal_value(value)
162
165
  begin
@@ -172,4 +175,4 @@ module CoffeeTable
172
175
  o.respond_to?(:id) || o.class == Class
173
176
  end
174
177
  end
175
- end
178
+ end
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coffee_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stewart McKee
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-17 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: redis
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rufus-scheduler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activesupport
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: sourcify
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: gzip
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: rails cache gem to fragment cache with smart cache key management
@@ -114,11 +101,11 @@ executables: []
114
101
  extensions: []
115
102
  extra_rdoc_files: []
116
103
  files:
117
- - .gitignore
118
- - .rspec
119
- - .ruby-gemset
120
- - .ruby-version
121
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-gemset"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
122
109
  - Gemfile
123
110
  - Gemfile.lock
124
111
  - README.textile
@@ -139,27 +126,26 @@ files:
139
126
  - spec/spec_helper.rb
140
127
  homepage: ''
141
128
  licenses: []
129
+ metadata: {}
142
130
  post_install_message:
143
131
  rdoc_options: []
144
132
  require_paths:
145
133
  - lib
146
134
  required_ruby_version: !ruby/object:Gem::Requirement
147
- none: false
148
135
  requirements:
149
- - - ! '>='
136
+ - - ">="
150
137
  - !ruby/object:Gem::Version
151
138
  version: '0'
152
139
  required_rubygems_version: !ruby/object:Gem::Requirement
153
- none: false
154
140
  requirements:
155
- - - ! '>='
141
+ - - ">="
156
142
  - !ruby/object:Gem::Version
157
143
  version: '0'
158
144
  requirements: []
159
145
  rubyforge_project: coffee_table
160
- rubygems_version: 1.8.25
146
+ rubygems_version: 2.5.1
161
147
  signing_key:
162
- specification_version: 3
148
+ specification_version: 4
163
149
  summary: Gem to manage cache stored in redis
164
150
  test_files:
165
151
  - spec/lib/coffee_table_spec.rb