Class: ProcessQueryLanguage::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/process-query-language/collection.rb

Instance Method Summary collapse

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, options)
  query[:pid] = query.delete(:_id) if query[:_id]

  keys = query.keys
  keys = keys + options[:fields] if options[: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, options)
  find(query, options).first
end

#insertObject



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