class DBEnvy
Constants
- VERSION
Attributes
uri[RW]
Public Class Methods
new()
click to toggle source
# File lib/dbenvy.rb, line 17 def initialize self.uri = URI.parse ENV['DATABASE_URL'] if ENV['DATABASE_URL'] end
to_hash()
click to toggle source
# File lib/dbenvy.rb, line 7 def self.to_hash new.to_hash end
yaml()
click to toggle source
# File lib/dbenvy.rb, line 11 def self.yaml new.yaml end
Public Instance Methods
to_hash()
click to toggle source
# File lib/dbenvy.rb, line 25 def to_hash credentials.merge options end
yaml()
click to toggle source
# File lib/dbenvy.rb, line 21 def yaml YAML.dump( { rails_env => to_hash } ) if uri && rails_env end
Private Instance Methods
credentials()
click to toggle source
# File lib/dbenvy.rb, line 35 def credentials { "adapter" => uri.scheme, "username" => uri.user, "password" => uri.password, "host" => uri.host, "port" => uri.port, "database" => database, } end
database()
click to toggle source
# File lib/dbenvy.rb, line 50 def database uri.path.dup.tap { |p| p.slice!("/") } end
options()
click to toggle source
# File lib/dbenvy.rb, line 46 def options Rack::Utils.parse_nested_query uri.query end
rails_env()
click to toggle source
# File lib/dbenvy.rb, line 31 def rails_env ENV['RAILS_ENV'] || "#{Rails.env}" if defined?(Rails) end