Class: Boxxspring::Journal
- Inherits:
-
Object
- Object
- Boxxspring::Journal
- Defined in:
- lib/boxxspring/journal.rb
Instance Method Summary collapse
- #delete(id) ⇒ Object
-
#initialize(name) ⇒ Journal
constructor
A new instance of Journal.
- #read(id) ⇒ Object
- #write(id, attributes) ⇒ Object
Constructor Details
#initialize(name) ⇒ Journal
Returns a new instance of Journal.
5 6 7 |
# File 'lib/boxxspring/journal.rb', line 5 def initialize( name ) @db_name = name end |
Instance Method Details
#delete(id) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/boxxspring/journal.rb', line 41 def delete( id ) db_record = self.db.delete_attributes( domain_name: @db_name, item_name: id.to_s ) end |
#read(id) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/boxxspring/journal.rb', line 23 def read( id ) result = nil db_record = self.db.get_attributes( domain_name: @db_name, item_name: id.to_s, consistent_read: true ) if db_record.present? && db_record.attributes.present? && db_record.attributes.length > 0 result = {} db_record.attributes.each do | attribute | result[ attribute.name.to_sym ] = attribute.value end end result end |
#write(id, attributes) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/boxxspring/journal.rb', line 9 def write( id, attributes ) db_attributes = [] attributes.each_pair do | key, value | db_attributes.push( { name: key.to_s, value: value.to_s, replace: true } ) end self.db.put_attributes( { domain_name: @db_name, item_name: id.to_s, attributes: db_attributes } ) end |