Class: Pione::Log::ProcessRecord
- Inherits:
-
Object
- Object
- Pione::Log::ProcessRecord
- Includes:
- SimpleIdentity
- Defined in:
- lib/pione/log/process-record.rb
Overview
ProcessRecord is a class that represents records of process log. Records are in tuple spaces and handled by PIONE's process logger agent. If you want to add record type, you need to create the subclass of this.
Direct Known Subclasses
AgentActivityProcessRecord, AgentConnectionProcessRecord, CreateChildTaskWorkerProcessRecord, PutDataProcessRecord, RuleProcessRecord, TaskProcessRecord
Constant Summary collapse
- TYPE_TABLE =
known process record types and classes
{}
Class Attribute Summary collapse
-
.fields ⇒ Array<Symbol>
readonly
Field names.
-
.type ⇒ String
readonly
Record type.
Instance Attribute Summary collapse
-
#log_id ⇒ String
Log_id.
-
#timestamp ⇒ Time
Record timestamp.
-
#transition ⇒ String
Transition name.
Class Method Summary collapse
-
.build(hash) ⇒ Object
Build a new record from hash table.
Instance Method Summary collapse
-
#format(log_id) ⇒ String
Format as a JSON string.
-
#initialize(data = {}) ⇒ ProcessRecord
constructor
Create a new process log record.
-
#merge(data) ⇒ ProcessRecord
Create a copy of the record and merge the data into it.
-
#to_hash ⇒ Hash
Convert the record into a hash table.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ ProcessRecord
Create a new process log record.
107 108 109 |
# File 'lib/pione/log/process-record.rb', line 107 def initialize(data={}) data.each {|key, val| send("%s=" % key, val) unless key == :type} end |
Class Attribute Details
.fields ⇒ Array<Symbol> (readonly)
Returns field names.
34 35 36 |
# File 'lib/pione/log/process-record.rb', line 34 def fields @fields end |
.type ⇒ String (readonly)
Returns record type.
30 31 32 |
# File 'lib/pione/log/process-record.rb', line 30 def type @type end |
Instance Attribute Details
#log_id ⇒ String
Returns log_id.
99 |
# File 'lib/pione/log/process-record.rb', line 99 field :log_id |
#timestamp ⇒ Time
Returns record timestamp.
89 |
# File 'lib/pione/log/process-record.rb', line 89 field :timestamp |
#transition ⇒ String
Returns transition name.
94 |
# File 'lib/pione/log/process-record.rb', line 94 field :transition |
Class Method Details
.build(hash) ⇒ Object
Build a new record from hash table.
39 40 41 42 43 44 45 |
# File 'lib/pione/log/process-record.rb', line 39 def build(hash) if klass = TYPE_TABLE[hash[:type].to_sym] klass.new(hash) else raise UnknownProcessRecordType.new(hash[:type]) end end |
Instance Method Details
#format(log_id) ⇒ String
Format as a JSON string.
127 128 129 |
# File 'lib/pione/log/process-record.rb', line 127 def format(log_id) JSON.dump(to_hash.merge(log_id: log_id)) end |
#merge(data) ⇒ ProcessRecord
Create a copy of the record and merge the data into it.
115 116 117 118 119 120 121 |
# File 'lib/pione/log/process-record.rb', line 115 def merge(data) ProcessRecord.build(to_hash).tap do |record| data.each do |key, val| record.send("%s=" % key, val) end end end |
#to_hash ⇒ Hash
Convert the record into a hash table.
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/pione/log/process-record.rb', line 135 def to_hash fields.inject({type: type}) do |table, name| table.tap do if val = send(name) val = val.iso8601(3) if name == :timestamp table[name] = val end end end end |
#to_json(*args) ⇒ Object
146 147 148 |
# File 'lib/pione/log/process-record.rb', line 146 def to_json(*args) to_hash.to_json(*args) end |