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.
-
#locales ⇒ Object
readonly
Returns the value of attribute locales.
-
#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.
-
#source_locale ⇒ Object
readonly
Returns the value of attribute source_locale.
-
#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
Returns a new instance of Database.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/txdb/database.rb', line 13 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) @locales = .fetch(:locales) @source_locale = .fetch(:source_locale) @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 |
#locales ⇒ Object (readonly)
Returns the value of attribute locales.
11 12 13 |
# File 'lib/txdb/database.rb', line 11 def locales @locales 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 |
#source_locale ⇒ Object (readonly)
Returns the value of attribute source_locale.
11 12 13 |
# File 'lib/txdb/database.rb', line 11 def source_locale @source_locale 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
31 32 33 |
# File 'lib/txdb/database.rb', line 31 def connection @connection ||= Sequel.connect(connection_string, max_connections: pool) end |
#find_table(name) ⇒ Object
43 44 45 46 |
# File 'lib/txdb/database.rb', line 43 def find_table(name) name = name.to_s tables.find { |table| table.name == name } end |
#from(*args, &block) ⇒ Object
35 36 37 |
# File 'lib/txdb/database.rb', line 35 def from(*args, &block) connection.from(*args, &block) end |
#transifex_api ⇒ Object
39 40 41 |
# File 'lib/txdb/database.rb', line 39 def transifex_api transifex_project.api end |