Class: Qs::Job
- Inherits:
-
Object
- Object
- Qs::Job
- Defined in:
- lib/qs/job.rb
Defined Under Namespace
Modules: StringifyParams
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, params, created_at = nil) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
- #to_payload ⇒ Object
Constructor Details
#initialize(name, params, created_at = nil) ⇒ Job
Returns a new instance of Job.
12 13 14 15 16 17 |
# File 'lib/qs/job.rb', line 12 def initialize(name, params, created_at = nil) validate!(name, params) @name = name @params = params @created_at = created_at || Time.now end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/qs/job.rb', line 10 def created_at @created_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/qs/job.rb', line 10 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/qs/job.rb', line 10 def params @params end |
Class Method Details
.parse(payload) ⇒ Object
5 6 7 8 |
# File 'lib/qs/job.rb', line 5 def self.parse(payload) created_at = Time.at(payload['created_at'].to_i) self.new(payload['name'], payload['params'], created_at) end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/qs/job.rb', line 34 def ==(other) if other.kind_of?(self.class) self.to_payload == other.to_payload else super end end |
#inspect ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/qs/job.rb', line 26 def inspect reference = '0x0%x' % (self.object_id << 1) "#<#{self.class}:#{reference} " \ "@name=#{self.name.inspect} " \ "@params=#{self.params.inspect} " \ "@created_at=#{self.created_at.inspect}>" end |
#to_payload ⇒ Object
19 20 21 22 23 24 |
# File 'lib/qs/job.rb', line 19 def to_payload { 'name' => self.name.to_s, 'params' => StringifyParams.new(self.params), 'created_at' => self.created_at.to_i } end |