Class: Txdb::Database
- Inherits:
-
Object
- Object
- Txdb::Database
- Defined in:
- lib/txdb/database.rb
Constant Summary collapse
- DEFAULT_HOST =
'127.0.0.1'
- DEFAULT_PORT =
'3306'
- DEFAULT_POOL =
10
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#connection_string ⇒ Object
readonly
Returns the value of attribute connection_string.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#transifex_project ⇒ Object
readonly
Returns the value of attribute transifex_project.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #connection ⇒ Object
- #find_table(name) ⇒ Object
- #from(*args, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Database
constructor
A new instance of Database.
- #transifex_api ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Database
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/txdb/database.rb', line 12 def initialize( = {}) @adapter = .fetch(:adapter) @backend = Txdb::Backends.get(.fetch(:backend)) @username = .fetch(:username) @password = .fetch(:password) @host = .fetch(:host, DEFAULT_HOST) @port = .fetch(:port, DEFAULT_PORT) @name = .fetch(:name) @pool = .fetch(:pool, DEFAULT_POOL) @transifex_project = TransifexProject.new(.fetch(:transifex)) @connection_string = ConnectionString.new().string @tables = .fetch(:tables).map do |table_config| Table.new(self, table_config) end end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def adapter @adapter end |
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def backend @backend end |
#connection_string ⇒ Object (readonly)
Returns the value of attribute connection_string.
10 11 12 |
# File 'lib/txdb/database.rb', line 10 def connection_string @connection_string end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def name @name end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def password @password end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
10 11 12 |
# File 'lib/txdb/database.rb', line 10 def pool @pool end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def port @port end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
10 11 12 |
# File 'lib/txdb/database.rb', line 10 def tables @tables end |
#transifex_project ⇒ Object (readonly)
Returns the value of attribute transifex_project.
10 11 12 |
# File 'lib/txdb/database.rb', line 10 def transifex_project @transifex_project end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/txdb/database.rb', line 9 def username @username end |
Instance Method Details
#connection ⇒ Object
28 29 30 |
# File 'lib/txdb/database.rb', line 28 def connection @connection ||= Sequel.connect(connection_string, max_connections: pool) end |
#find_table(name) ⇒ Object
40 41 42 43 |
# File 'lib/txdb/database.rb', line 40 def find_table(name) name = name.to_s tables.find { |table| table.name == name } end |
#from(*args, &block) ⇒ Object
32 33 34 |
# File 'lib/txdb/database.rb', line 32 def from(*args, &block) connection.from(*args, &block) end |
#transifex_api ⇒ Object
36 37 38 |
# File 'lib/txdb/database.rb', line 36 def transifex_api transifex_project.api end |