Class: Sohm::Set
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#combine(dict) ⇒ Object
Perform an intersection between the existent set and the new set created by the union of the passed filters.
-
#except(dict) ⇒ Object
Reduce the set using any number of filters.
-
#find(dict) ⇒ Object
Chain new fiters on an existing set.
-
#initialize(key, namespace, model) ⇒ Set
constructor
A new instance of Set.
-
#union(dict) ⇒ Object
Do a union to the existing set using any number of filters.
Methods inherited from BasicSet
#[], #exists?, #ids, #include?, #sample, #size
Methods included from Collection
#each, #empty?, #fetch, #to_a, #to_json
Constructor Details
#initialize(key, namespace, model) ⇒ Set
Returns a new instance of Set.
413 414 415 416 417 |
# File 'lib/sohm.rb', line 413 def initialize(key, namespace, model) @key = key @namespace = namespace @model = model end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
409 410 411 |
# File 'lib/sohm.rb', line 409 def key @key end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
411 412 413 |
# File 'lib/sohm.rb', line 411 def model @model end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
410 411 412 |
# File 'lib/sohm.rb', line 410 def namespace @namespace end |
Instance Method Details
#combine(dict) ⇒ Object
Perform an intersection between the existent set and the new set created by the union of the passed filters.
Example:
set = User.find(:status => "active")
set.combine(:name => ["John", "Jane"])
# The result will include all users with active status
# and with names "John" or "Jane".
456 457 458 |
# File 'lib/sohm.rb', line 456 def combine(dict) MultiSet.new(namespace, model, key).combine(dict) end |
#except(dict) ⇒ Object
Reduce the set using any number of filters.
Example:
set = User.find(:name => "John")
set.except(:country => "US")
# You can also do it in one line.
User.find(:name => "John").except(:country => "US")
442 443 444 |
# File 'lib/sohm.rb', line 442 def except(dict) MultiSet.new(namespace, model, key).except(dict) end |
#find(dict) ⇒ Object
Chain new fiters on an existing set.
Example:
set = User.find(:name => "John")
set.find(:age => 30)
426 427 428 429 430 |
# File 'lib/sohm.rb', line 426 def find(dict) MultiSet.new( namespace, model, Command[:sinterstore, key, *model.filters(dict)] ) end |
#union(dict) ⇒ Object
Do a union to the existing set using any number of filters.
Example:
set = User.find(:name => "John")
set.union(:name => "Jane")
# You can also do it in one line.
User.find(:name => "John").union(:name => "Jane")
470 471 472 |
# File 'lib/sohm.rb', line 470 def union(dict) MultiSet.new(namespace, model, key).union(dict) end |