Class: EY::Snaplock::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_snaplock/database.rb,
lib/ey_snaplock/database/mysql.rb,
lib/ey_snaplock/database/postgresql9.rb

Defined Under Namespace

Classes: MySQL, Postgresql

Class Method Summary collapse

Class Method Details

.for(database_uri) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ey_snaplock/database.rb', line 7

def self.for(database_uri)
  uri = parse_uri(database_uri)
  # Determine what kind of database we need to snaplock, current two supported schemes are:
  # mysql://root:password@localhost/
  # postgres9:://postgres:localhost/
  case uri.scheme
  when 'mysql'
    MySQL.new(uri)
  when "postgres9"
    Postgresql.new(uri)
    # Unknown url schema provided, print the error message and exit with an exit code of 1
  else
    abort "Don't know how to lock database with URI: #{database_uri.inspect}"
  end
end

.parse_uri(uri) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/ey_snaplock/database.rb', line 23

def self.parse_uri(uri)
  begin
    Addressable::URI.parse(uri)
  rescue TypeError, Addressable::URI::InvalidURIError
    $stderr.puts "Error parsing database URI: #{uri.inspect}"
    raise
  end
end