Class: RQ::Job

Inherits:
Array show all
Includes:
ArrayFields
Defined in:
lib/rq/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 Attribute Summary

Attributes included from Fieldable

#fieldset

Instance Method Summary collapse

Methods included from ArrayFields

#[], #[]=, #at, #delete_at, #each_key, #each_pair, #each_value, #each_with_field, #fetch, #fill, #has_key?, #has_value?, #indexes, #indices, #invert, #key?, #keys, #member?, #replace, #slice, #slice!, #store, #to_h, #to_hash, #update, #value?, #values, #values_at, version

Methods inherited from Array

fields

Methods included from Fieldable

#fields, #fields=

Constructor Details

#initialize(kvs = {}) ⇒ Job

Returns a new instance of Job.



20
21
22
23
24
25
# File 'lib/rq/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/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/job.rb', line 43

def to_yaml
  to_hash.to_yaml
end