Module: Aws::SiteMonitor::PstoreRecord
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/aws/site_monitor/pstore_record.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #attributes ⇒ Object
- #destroy ⇒ Object
- #initialize(id: ::SecureRandom.hex(16), **_attributes) ⇒ Object
- #save ⇒ Object
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 |
#attributes ⇒ Object
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 |
#destroy ⇒ Object
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 |
#save ⇒ Object
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 |