Class: CapTaffy::Parse

Inherits:
Heroku::Command::Db
  • Object
show all
Defined in:
lib/cap-taffy/parse.rb

Defined Under Namespace

Classes: Invalid

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParse

Override to do nothing on #new



40
41
42
# File 'lib/cap-taffy/parse.rb', line 40

def initialize # :nodoc:

end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



14
15
16
# File 'lib/cap-taffy/parse.rb', line 14

def instance
  @instance
end

Class Method Details

.database_url(db_config, env) ⇒ Object

Modified from :parse_database_yml in heroku/command/db.rb

Accepts a complete db_config hash and env and parses for a database_url accordingly.

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cap-taffy/parse.rb', line 19

def database_url(db_config, env)
  raise Invalid, "please pass me a valid Hash loaded from a database YAML file" unless db_config
  conf = db_config[env]
  raise Invalid, "missing '#{env}' database in #{db_config.inspect}" unless conf

  self.instance ||= CapTaffy::Parse.new

  case conf['adapter']
  when 'sqlite3'
    return "sqlite://#{conf['database']}"
  when 'postgresql'
    uri_hash = self.instance.conf_to_uri_hash(conf)
    uri_hash['scheme'] = 'postgres'
    return self.instance.uri_hash_to_url(uri_hash)
  else
    return self.instance.uri_hash_to_url(self.instance.conf_to_uri_hash(conf))
  end
end

Instance Method Details

#escape(string) ⇒ Object

Override to pass-through on #escape



45
46
47
# File 'lib/cap-taffy/parse.rb', line 45

def escape(string)
  string
end