Class: Sequelinha::ConnectionURL

Inherits:
Object
  • Object
show all
Defined in:
lib/sequelinha/connection_url.rb

Direct Known Subclasses

Adapters::Postgres, Adapters::Sqlite

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ConnectionURL

Returns a new instance of ConnectionURL.



3
4
5
# File 'lib/sequelinha/connection_url.rb', line 3

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/sequelinha/connection_url.rb', line 7

def config
  @config
end

Class Method Details

.=~(adapter) ⇒ Object



10
11
12
# File 'lib/sequelinha/connection_url.rb', line 10

def =~(adapter)
  nil
end

Instance Method Details

#adapterObject



27
28
29
# File 'lib/sequelinha/connection_url.rb', line 27

def adapter
  @config["adapter"]
end

#application_rootObject



15
16
17
# File 'lib/sequelinha/connection_url.rb', line 15

def application_root
  @config["application_root"]
end

#databaseObject



31
32
33
# File 'lib/sequelinha/connection_url.rb', line 31

def database
  @config["database"]
end

#hostObject



35
36
37
# File 'lib/sequelinha/connection_url.rb', line 35

def host
  @config["host"] || "localhost"
end

#passwordObject



23
24
25
# File 'lib/sequelinha/connection_url.rb', line 23

def password
  @config["password"]
end

#stringObject



39
40
41
42
43
44
45
# File 'lib/sequelinha/connection_url.rb', line 39

def string
  final_url =  "#{self.adapter}://"
  final_url << "#{self.username}:" if self.username
  final_url << "#{self.password}" if self.password
  final_url << "@#{self.host}" if self.host
  final_url << "/#{self.database}" if self.database
end

#usernameObject



19
20
21
# File 'lib/sequelinha/connection_url.rb', line 19

def username
  @config["username"]
end