Skip to content

Commit

Permalink
pass --db to info
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed Mar 17, 2011
1 parent d89ca22 commit 3e8791a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 14 additions & 2 deletions init.rb
Expand Up @@ -15,7 +15,11 @@ def psql
end

def info
Resolver.all(config_vars).each { |db| display_db_info db }
if db_flag
display_db_info Resolver.new(db_flag, config_vars)
else
Resolver.all(config_vars).each { |db| display_db_info db }
end
end

private
Expand Down Expand Up @@ -70,8 +74,12 @@ def generate_ingress_uri(action)
return URI.parse(url)
end

def db_flag
@db_flag ||= extract_option("--db")
end

def resolve_db
db_id = extract_option("--db") || "DATABASE"
db_id = db_flag || "DATABASE"
config_vars = heroku.config_vars(app)

resolver = Resolver.new(db_id, config_vars)
Expand Down Expand Up @@ -101,6 +109,10 @@ def message
@messages.join("\n") unless @messages.empty?
end

def [](arg)
{:name => db_id, :url => url, :default => url==@dbs['DATABASE']}[arg]
end

def self.all(config_vars)
parsed = parse_config(config_vars)
default = parsed['DATABASE']
Expand Down
10 changes: 8 additions & 2 deletions pg_spec.rb
Expand Up @@ -6,9 +6,15 @@

describe Pg::Resolver do
context "pass in *_URL" do
let(:r) { Pg::Resolver.new "HEROKU_POSTGRESQL_SOME_URL", "HEROKU_POSTGRESQL_SOME_URL" => 'something'}

it 'should warn to not add in _URL, and proceed without it' do
r = Pg::Resolver.new "SOME_URL", "SOME_URL" => 'something'
r.message.should == "SOME_URL is deprecated, please use SOME"
r.message.should == "HEROKU_POSTGRESQL_SOME_URL is deprecated, please use HEROKU_POSTGRESQL_SOME\nusing SOME"
end

it 'should have [] access' do
r[:url].should == 'something'
r[:name].should == 'SOME'
end
end

Expand Down

0 comments on commit 3e8791a

Please sign in to comment.