Class: RedisTags::RedisTag
- Inherits:
-
Object
- Object
- RedisTags::RedisTag
- Defined in:
- lib/redis_tags/redis_tag.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#owner_class ⇒ Object
readonly
Returns the value of attribute owner_class.
Class Method Summary collapse
- .has_tags(klass, options = {}) ⇒ Object
- .register_tag_for_autocomplete(use_engine, tag_name) ⇒ Object
- .starts_with?(use_engine, partial_tag_name) ⇒ Boolean
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(owner, name) ⇒ RedisTag
constructor
A new instance of RedisTag.
Constructor Details
#initialize(owner, name) ⇒ RedisTag
Returns a new instance of RedisTag.
8 9 10 11 12 |
# File 'lib/redis_tags/redis_tag.rb', line 8 def initialize(owner, name) @owner_class = owner.class.to_s.downcase @name = name.downcase.strip @owner = owner end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/redis_tags/redis_tag.rb', line 3 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
6 7 8 |
# File 'lib/redis_tags/redis_tag.rb', line 6 def owner @owner end |
#owner_class ⇒ Object (readonly)
Returns the value of attribute owner_class.
4 5 6 |
# File 'lib/redis_tags/redis_tag.rb', line 4 def owner_class @owner_class end |
Class Method Details
.has_tags(klass, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/redis_tags/redis_tag.rb', line 30 def self.(klass, = {}) key_array = [] if [:tags].to_a.size == 1 if [:random].to_i > 0 klass..zrandmember RedisTags::RedisTag.tagged_with_key_for(klass, [:tags]), [:random].to_i elsif [:since] klass..zrangebyscore RedisTags::RedisTag.tagged_with_key_for(klass, [:tags]), [:since].to_i, Time.now.to_i else klass..zrangebyscore RedisTags::RedisTag.tagged_with_key_for(klass, [:tags]), Time.now.to_i - 7 * 60 * 60 * 24, Time.now.to_i end else [:tags].to_a.each do |tag_name| key_array << RedisTag.tagged_with_key_for(klass, tag_name) end klass..zinterstore RedisTags::RedisTag.intersect_key_for(klass, [:tags]), key_array, {:aggregate => :max} if [:random].to_i > 0 klass..zrandmember RedisTags::RedisTag.intersect_key_for(klass, [:tags]), [:random].to_i elsif [:since] klass..zrangebyscore RedisTags::RedisTag.intersect_key_for(klass, [:tags]), [:since].to_i, Time.now.to_i else klass..zrangebyscore RedisTags::RedisTag.intersect_key_for(klass, [:tags]), (Time.now.to_i - 7 * 60 * 60 * 24), Time.now.to_i end end end |
.register_tag_for_autocomplete(use_engine, tag_name) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/redis_tags/redis_tag.rb', line 18 def self.register_tag_for_autocomplete(use_engine, tag_name) partial_tag_name = "" tag_name.each_char do |char| partial_tag_name += char use_engine.sadd "tags:all:#{partial_tag_name}", tag_name end end |
.starts_with?(use_engine, partial_tag_name) ⇒ Boolean
14 15 16 |
# File 'lib/redis_tags/redis_tag.rb', line 14 def self.starts_with?(use_engine, partial_tag_name) use_engine.smembers "tags:all:#{partial_tag_name}" end |
Instance Method Details
#count ⇒ Object
26 27 28 |
# File 'lib/redis_tags/redis_tag.rb', line 26 def count engine.zcard redis_key end |