Class: AstDB::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/astdb/models/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Database

Returns a new instance of Database.



6
7
8
9
10
11
12
13
14
15
# File 'lib/astdb/models/database.rb', line 6

def initialize(opts = {})
  @connection  = Connection.new host:     opts[:host],
                                username: opts[:username],
                                password: opts[:password]
                                
  @auto_reload  = opts[:auto_reload].nil? ? true : opts[:auto_reload]
  @database     = {}

  reload_database if @auto_reload
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/astdb/models/database.rb', line 4

def connection
  @connection
end

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'lib/astdb/models/database.rb', line 4

def hash
  @hash
end

Instance Method Details

#reload_databaseObject



24
25
26
# File 'lib/astdb/models/database.rb', line 24

def reload_database
  @hash = @connection.fetch_database
end

#set(value_hash) ⇒ Object



17
18
19
20
21
22
# File 'lib/astdb/models/database.rb', line 17

def set(value_hash)
  errors = @connection.set_database_values(value_hash)
  reload_database if @auto_reload
  
  errors
end