Class: Pasqual::Database

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Database

Returns a new instance of Database.



11
12
13
14
15
16
17
18
# File 'lib/pasqual/database.rb', line 11

def initialize(url)
  uri = URI.parse url
  @username = uri.user
  @password = uri.password
  @host = uri.host
  @port = uri.port
  @name = uri.path.sub(/^\//, '')
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/pasqual/database.rb', line 9

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/pasqual/database.rb', line 9

def name
  @name
end

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/pasqual/database.rb', line 9

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/pasqual/database.rb', line 9

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/pasqual/database.rb', line 9

def username
  @username
end

Instance Method Details

#command(statement) ⇒ Object



32
33
34
# File 'lib/pasqual/database.rb', line 32

def command(statement)
  Psql.command statement, username, password, host, port, name
end

#createdb(create_name = name) ⇒ Object



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

def createdb(create_name = name)
  Createdb.execute username, password, host, port, create_name
end

#dropdb(drop_name = name) ⇒ Object



28
29
30
# File 'lib/pasqual/database.rb', line 28

def dropdb(drop_name = name)
  Dropdb.execute username, password, host, port, drop_name
end

#pipe_sql(file, dbname = name) ⇒ Object



36
37
38
# File 'lib/pasqual/database.rb', line 36

def pipe_sql(file, dbname = name)
  Psql.pipe file, username, password, host, port, dbname
end