Module: JSONdb::Records
- Included in:
- Table
- Defined in:
- lib/jsondb/records.rb
Instance Method Summary collapse
- #delete_record(record) ⇒ Object (also: #drop_record)
- #exists?(record) ⇒ Boolean
- #insert_record(record) ⇒ Object
- #new_record ⇒ Object
- #record(key) ⇒ Object
- #record_count ⇒ Object (also: #count)
- #records ⇒ Object
- #records_to_hash ⇒ Object
- #update_record(record) ⇒ Object
Instance Method Details
#delete_record(record) ⇒ Object Also known as: drop_record
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jsondb/records.rb', line 32 def delete_record(record) begin @persisted = false JSONdb.records[@name][record.id] = nil JSONdb.records[@name].delete(record.id) record = nil return true rescue return false end end |
#exists?(record) ⇒ Boolean
46 47 48 |
# File 'lib/jsondb/records.rb', line 46 def exists?(record) !JSONdb.records[@name][record.id].nil? end |
#insert_record(record) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/jsondb/records.rb', line 17 def insert_record(record) @persisted = false @updated_at = Time.now.to_i # updated table updated_at time record.id = new_id record.created_at = Time.now.to_i record.updated_at = Time.now.to_i JSONdb.records[@name][record.id] = record end |
#new_record ⇒ Object
13 14 15 |
# File 'lib/jsondb/records.rb', line 13 def new_record return JSONdb::Record.new(@name) end |
#record(key) ⇒ Object
5 6 7 |
# File 'lib/jsondb/records.rb', line 5 def record(key) JSONdb.records[@name][key] end |
#record_count ⇒ Object Also known as: count
50 51 52 |
# File 'lib/jsondb/records.rb', line 50 def record_count JSONdb.records[@name].keys.count end |
#records ⇒ Object
9 10 11 |
# File 'lib/jsondb/records.rb', line 9 def records JSONdb.records[@name] end |