Class: JSONdb::Table
- Inherits:
-
Object
- Object
- JSONdb::Table
- Includes:
- Fields, Logger, Records, Validations::Naming
- Defined in:
- lib/jsondb/table.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#last_id ⇒ Object
Returns the value of attribute last_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#persisted ⇒ Object
readonly
Returns the value of attribute persisted.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(name, new_table = true) ⇒ Table
constructor
A new instance of Table.
- #persist ⇒ Object
- #to_hash ⇒ Object
Methods included from Records
#delete_record, #exists?, #insert_record, #new_record, #record, #record_count, #records, #records_to_hash, #update_record
Methods included from Fields
#add_main_fields, #create_field, #drop_field, #field, #fields, #fields_to_hash
Methods included from Logger
#allowed_log_level?, #log, #log_enabled?, #log_this?
Methods included from Validations::Naming
Constructor Details
#initialize(name, new_table = true) ⇒ Table
Returns a new instance of Table.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jsondb/table.rb', line 13 def initialize(name, new_table = true) @name = name @persisted = false JSONdb.records[@name] = JSONdb::PaginatedHash.new JSONdb.fields[@name] = Hash.new set_defaults add_main_fields init_table(new_table) end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
11 12 13 |
# File 'lib/jsondb/table.rb', line 11 def created_at @created_at end |
#last_id ⇒ Object
Returns the value of attribute last_id.
11 12 13 |
# File 'lib/jsondb/table.rb', line 11 def last_id @last_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/jsondb/table.rb', line 10 def name @name end |
#persisted ⇒ Object (readonly)
Returns the value of attribute persisted.
10 11 12 |
# File 'lib/jsondb/table.rb', line 10 def persisted @persisted end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/jsondb/table.rb', line 11 def @timestamp end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
11 12 13 |
# File 'lib/jsondb/table.rb', line 11 def updated_at @updated_at end |
Instance Method Details
#destroy ⇒ Object
43 44 45 |
# File 'lib/jsondb/table.rb', line 43 def destroy @file.destroy end |
#persist ⇒ Object
26 27 28 29 30 |
# File 'lib/jsondb/table.rb', line 26 def persist @persisted = true @file.contents = records_to_hash @file.write end |
#to_hash ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jsondb/table.rb', line 32 def to_hash { @name => { "created_at" => @created_at, "updated_at" => @updated_at, "last_id" => @last_id, "fields" => fields_to_hash }, } end |