Class: SDM::ResourceHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/models/porcelain.rb

Overview

ResourceHistory records the state of a Resource at a given point in time, where every change (create, update and delete) to a Resource produces an ResourceHistory record.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(activity_id: nil, deleted_at: nil, resource: nil, timestamp: nil) ⇒ ResourceHistory

Returns a new instance of ResourceHistory.



10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
# File 'lib/models/porcelain.rb', line 10320

def initialize(
  activity_id: nil,
  deleted_at: nil,
  resource: nil,
  timestamp: nil
)
  @activity_id = activity_id == nil ? "" : activity_id
  @deleted_at = deleted_at == nil ? nil : deleted_at
  @resource = resource == nil ? nil : resource
  @timestamp = timestamp == nil ? nil : timestamp
end

Instance Attribute Details

#activity_idObject

The unique identifier of the Activity that produced this change to the Resource. May be empty for some system-initiated updates.



10312
10313
10314
# File 'lib/models/porcelain.rb', line 10312

def activity_id
  @activity_id
end

#deleted_atObject

If this Resource was deleted, the time it was deleted.



10314
10315
10316
# File 'lib/models/porcelain.rb', line 10314

def deleted_at
  @deleted_at
end

#resourceObject

The complete Resource state at this time.



10316
10317
10318
# File 'lib/models/porcelain.rb', line 10316

def resource
  @resource
end

#timestampObject

The time at which the Resource state was recorded.



10318
10319
10320
# File 'lib/models/porcelain.rb', line 10318

def timestamp
  @timestamp
end

Instance Method Details

#to_json(options = {}) ⇒ Object



10332
10333
10334
10335
10336
10337
10338
# File 'lib/models/porcelain.rb', line 10332

def to_json(options = {})
  hash = {}
  self.instance_variables.each do |var|
    hash[var.id2name.delete_prefix("@")] = self.instance_variable_get var
  end
  hash.to_json
end