cachetastic 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,8 @@ class Cachetastic::Adapters::File < Cachetastic::Adapters::Base
45
45
  require so.value.class.underscore
46
46
  so = YAML::load(File.open(full_path).read)
47
47
  end
48
+ puts so.value.class
49
+ pp so.value
48
50
  return so.value
49
51
  end
50
52
  return nil
@@ -139,7 +139,12 @@ class Cachetastic::Caches::Base
139
139
 
140
140
  # Returns the underlying Cachetastic::Adapters::Base for this cache.
141
141
  def adapter
142
- cache_conn_instance.get(cache_name)
142
+ a = cache_conn_instance.get(cache_name)
143
+ if adapter_supported?(a.class)
144
+ return a
145
+ else
146
+ raise Cachetastic::Errors::UnsupportedAdapter.new(cache_name, a.class)
147
+ end
143
148
  end
144
149
 
145
150
  # Returns the Cachetastic::Logger for the underlying Cachetastic::Adapters::Base.
@@ -147,6 +152,18 @@ class Cachetastic::Caches::Base
147
152
  adapter.logger
148
153
  end
149
154
 
155
+ # Returns an array of unsupported adapters for this cache. Defaults to an empty
156
+ # array which will let any adapter be used by the cache. Override in your specific
157
+ # cache to prevent certain adapters.
158
+ def unsupported_adapters
159
+ []
160
+ end
161
+
162
+ # Returns true/false on whether the adapter you want to use is supported for the cache.
163
+ def adapter_supported?(a = cache_conn_instance.get(cache_name).class)
164
+ return !unsupported_adapters.include?(a)
165
+ end
166
+
150
167
  private
151
168
  # If the expiry time is set to 60 minutes and the expiry_swing time is set to
152
169
  # 15 minutes, this method will return a number between 45 minutes and 75 minutes.
@@ -1,3 +1,12 @@
1
1
  # Used for storing Rails sessions.
2
2
  class Cachetastic::Caches::RailsSessionCache < Cachetastic::Caches::Base
3
+
4
+ class << self
5
+
6
+ def unsupported_adapters
7
+ [Cachetastic::Adapters::File]
8
+ end
9
+
10
+ end
11
+
3
12
  end
data/lib/cachetastic.rb CHANGED
@@ -14,6 +14,8 @@ module Cachetastic #:nodoc:#
14
14
  end
15
15
  module Adapters #:nodoc:#
16
16
  end
17
+ module Errors #:nodoc:#
18
+ end
17
19
  module Helpers #:nodoc:#
18
20
  module ActiveRecord #:nodoc:#
19
21
  end
@@ -27,6 +29,7 @@ require 'cachetastic_logger'
27
29
  require 'caches/cachetastic_caches_base'
28
30
  require 'caches/cachetastic_caches_page_cache'
29
31
  require 'caches/cachetastic_caches_rails_session_cache'
32
+ require 'errors/cachetastic_errors_unsupported_adapter'
30
33
  require 'adapters/cachetastic_adapters_base'
31
34
  require 'adapters/cachetastic_adapters_store_object'
32
35
  require 'adapters/cachetastic_adapters_memcache'
@@ -0,0 +1,7 @@
1
+ class Cachetastic::Errors::UnsupportedAdapter < Exception
2
+
3
+ def initialize(cache_name, adapter)
4
+ super("#{cache_name} does not support the use of the #{adapter} adapter!")
5
+ end
6
+
7
+ end
@@ -2,4 +2,4 @@
2
2
  gem_name: cachetastic
3
3
  package: cachetastic
4
4
  project: magrathea
5
- version: 1.2.1
5
+ version: 1.2.2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -123,6 +123,7 @@ files:
123
123
  - lib/cachetastic.rb
124
124
  - lib/cachetastic_connection.rb
125
125
  - lib/cachetastic_logger.rb
126
+ - lib/errors/cachetastic_errors_unsupported_adapter.rb
126
127
  - lib/helpers/cachetastic_helpers_active_record.rb
127
128
  - lib/rails_extensions/cachetastic_active_record_base.rb
128
129
  - lib/rails_extensions/cgi_session_cachetastic_store.rb