Class: Commendo::MySqlBacked::TagSet
- Inherits:
-
Object
- Object
- Commendo::MySqlBacked::TagSet
- Defined in:
- lib/commendo/mysql-backed/tag_set.rb
Instance Attribute Summary collapse
-
#key_base ⇒ Object
Returns the value of attribute key_base.
-
#mysql ⇒ Object
Returns the value of attribute mysql.
Instance Method Summary collapse
- #add(resource, *tags) ⇒ Object
- #delete(resource, *tags) ⇒ Object
- #empty? ⇒ Boolean
- #get(resource) ⇒ Object
-
#initialize(key_base) ⇒ TagSet
constructor
A new instance of TagSet.
- #matches(resource, include, exclude = []) ⇒ Object
- #set(resource, *tags) ⇒ Object
Constructor Details
Instance Attribute Details
#key_base ⇒ Object
Returns the value of attribute key_base.
5 6 7 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 5 def key_base @key_base end |
#mysql ⇒ Object
Returns the value of attribute mysql.
5 6 7 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 5 def mysql @mysql end |
Instance Method Details
#add(resource, *tags) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 23 def add(resource, *) return if .empty? @mysql.transaction do |client| (resource, ) end end |
#delete(resource, *tags) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 44 def delete(resource, *) if .empty? .execute(@key_base, resource) else .each { |t| .execute(@key_base, resource, t) } end end |
#empty? ⇒ Boolean
13 14 15 16 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 13 def empty? result = empty_prepared_query.execute(@key_base) result.count.zero? end |
#get(resource) ⇒ Object
18 19 20 21 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 18 def get(resource) result = .execute(@key_base, resource) result.map { |r| r['tag'] } end |
#matches(resource, include, exclude = []) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 37 def matches(resource, include, exclude = []) = get(resource) can_include = include.nil? || include.empty? || ( & include).length > 0 should_exclude = !exclude.nil? && !exclude.empty? && ( & exclude).length > 0 return can_include && !should_exclude end |
#set(resource, *tags) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/commendo/mysql-backed/tag_set.rb', line 30 def set(resource, *) @mysql.transaction do |client| delete(resource) (resource, ) unless .empty? end end |