Class: ProcessQueryLanguage::Collection
- Inherits:
-
Object
- Object
- ProcessQueryLanguage::Collection
- Defined in:
- lib/process-query-language/collection.rb
Instance Method Summary collapse
- #find(query, options) ⇒ Object
- #find_one(query, options) ⇒ Object
-
#initialize(backend) ⇒ Collection
constructor
A new instance of Collection.
- #insert ⇒ Object
- #remove(query) ⇒ Object
Constructor Details
#initialize(backend) ⇒ Collection
Returns a new instance of Collection.
6 7 8 |
# File 'lib/process-query-language/collection.rb', line 6 def initialize(backend) @backend = backend end |
Instance Method Details
#find(query, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/process-query-language/collection.rb', line 10 def find(query, ) query[:pid] = query.delete(:_id) if query[:_id] keys = query.keys keys = keys + [:fields] if [:fields] matcher = ProcessQueryLanguage::Matcher.new(query) result = [] @backend.scan(keys.uniq).each do |process| if matcher.match(process) result << process end end return result end |
#find_one(query, options) ⇒ Object
27 28 29 |
# File 'lib/process-query-language/collection.rb', line 27 def find_one(query, ) find(query, ).first end |
#insert ⇒ Object
37 38 |
# File 'lib/process-query-language/collection.rb', line 37 def insert end |
#remove(query) ⇒ Object
31 32 33 34 35 |
# File 'lib/process-query-language/collection.rb', line 31 def remove(query) find(query, { :fields => [ :pid ] }).each do |process| Process.kill(process[:pid]) end end |