Class: RQ::Job

Inherits:
Array
  • Object
show all
Includes:
ArrayFields
Defined in:
lib/rq-3.0.0/job.rb

Overview

Job is a convenience class which stamps out a QDB::tuple and extends it with methods that give accessor methods for each field in the hash

Instance Method Summary collapse

Constructor Details

#initialize(kvs = {}) ⇒ Job

Returns a new instance of Job.



20
21
22
23
24
25
# File 'lib/rq-3.0.0/job.rb', line 20

def initialize kvs = {}
#--{{{
  self.fields = QDB::FIELDS
  (kvs.keys - self.fields).each{|k| self[k] = kvs[k]}
#--}}}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

–}}}



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rq-3.0.0/job.rb', line 26

def method_missing(meth, *args, &block)
#--{{{
  setpat = %r/=$/o
  meth = "#{ meth }"
  setter = meth =~ setpat 
  meth.gsub! setpat, ''
  if fields.include? "#{ meth }"
    if setter
      self.send('[]=', meth, *args, &block)
    else
      self.send('[]', meth, *args, &block)
    end
  else
    super
  end
#--}}}
end

Instance Method Details

#to_yamlObject

–}}}



43
44
45
# File 'lib/rq-3.0.0/job.rb', line 43

def to_yaml
  to_hash.to_yaml
end