Class: TaggableCache::Store::Base
- Inherits:
-
Object
- Object
- TaggableCache::Store::Base
- Defined in:
- lib/taggable_cache/store/base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add(tag, *members) ⇒ Object
:nodoc:.
-
#get(*members) ⇒ Object
:nodoc:.
-
#id_for(obj) ⇒ Object
Returns taggable cache unique id for object.
-
#in_scope?(scope, object) ⇒ Boolean
Checks if object is in given scope.
-
#initialize(attrs = {}) ⇒ Base
constructor
:nodoc:.
-
#is_scope?(scope) ⇒ Boolean
Checks if this is AR scope.
Constructor Details
#initialize(attrs = {}) ⇒ Base
:nodoc:
45 46 47 |
# File 'lib/taggable_cache/store/base.rb', line 45 def initialize(attrs = {}) raise ActionController::NotImplemented.new end |
Instance Method Details
#add(tag, *members) ⇒ Object
:nodoc:
50 51 52 |
# File 'lib/taggable_cache/store/base.rb', line 50 def add(tag, *members) raise ActionController::NotImplemented.new end |
#get(*members) ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/taggable_cache/store/base.rb', line 55 def get(*members) raise ActionController::NotImplemented.new end |
#id_for(obj) ⇒ Object
Returns taggable cache unique id for object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/taggable_cache/store/base.rb', line 4 def id_for(obj) if obj.is_a? Class obj.to_s.downcase elsif obj.is_a? ActiveRecord::Base if obj.persisted? "#{obj.class.to_s.downcase}-#{obj.id}" else id_for(obj.class) end elsif obj.is_a? Arel::SelectManager "query-keys-#{Digest::MD5.hexdigest(obj.to_sql)}" elsif obj.is_a? ActiveRecord::Relation id_for(obj.arel) elsif obj.is_a? String "string_#{obj.to_s}" elsif obj.is_a? Hash if obj.include?(:cls) && obj.include?(:id) "#{obj[:cls].to_s.downcase}-#{obj[:id]}" else nil end else nil end end |
#in_scope?(scope, object) ⇒ Boolean
Checks if object is in given scope
36 37 38 39 40 41 42 |
# File 'lib/taggable_cache/store/base.rb', line 36 def in_scope?(scope, object) return false unless object.persisted? query = scope.where(scope.froms.first[:id].eq(object.id)).to_sql object.class.connection.select_all(query).length > 0 end |
#is_scope?(scope) ⇒ Boolean
Checks if this is AR scope
31 32 33 |
# File 'lib/taggable_cache/store/base.rb', line 31 def is_scope?(scope) (scope.is_a? ActiveRecord::Relation) || (scope.is_a? Arel::SelectManager) end |