Module: Aws::SiteMonitor::PstoreRecord

Extended by:
ActiveSupport::Concern
Included in:
Event, Site
Defined in:
lib/aws/site_monitor/pstore_record.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#[](k) ⇒ Object



52
53
54
# File 'lib/aws/site_monitor/pstore_record.rb', line 52

def [](k)
  instance_variable_get(:"@#{k}")
end

#[]=(k, v) ⇒ Object



56
57
58
# File 'lib/aws/site_monitor/pstore_record.rb', line 56

def []=(k,v)
  instance_variable_set(:"@#{k}", v)
end

#attributesObject



68
69
70
71
72
73
# File 'lib/aws/site_monitor/pstore_record.rb', line 68

def attributes
  instance_variables.each_with_object({}) do |k, obj|
    key = k[1,k.length]
    obj[key] = self[key]
  end.symbolize_keys
end

#destroyObject



75
76
77
78
79
80
81
# File 'lib/aws/site_monitor/pstore_record.rb', line 75

def destroy
  self.class.database.transaction do
    self.class.database.delete(self[:id])
  end

  true
end

#initialize(id: ::SecureRandom.hex(16), **_attributes) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/aws/site_monitor/pstore_record.rb', line 60

def initialize(id: ::SecureRandom.hex(16), **_attributes)
  self['id'] = id

  _attributes.each_pair do |k,v|
    self[k] = v
  end
end

#saveObject



84
85
86
87
88
89
90
91
# File 'lib/aws/site_monitor/pstore_record.rb', line 84

def save
  records = self.class.database

  records.transaction do
    records[@id] = self.attributes.symbolize_keys
    records.commit
  end
end