Skip to content

Commit

Permalink
fix for psql address with no user, pw (localhost by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvreynolds committed Feb 10, 2017
1 parent 2cb9221 commit 27aed86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions factory_bro.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'factory_bro'
s.version = '0.0.6'
s.date = '2016-10-27'
s.version = '0.0.7'
s.date = '2017-02-10'
s.summary = "Factory Bro"
s.description = "PSQL Parser and Data Generation similar to factory_girl"
s.authors = ["Nate Reynolds"]
Expand Down
12 changes: 8 additions & 4 deletions lib/factory_bro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ def self.generate_data(name, table, data)
private

def self.parse_url(url)
{ :user => url.scan(/postgres:..[A-Za-z0-9]+/).first.split('//')[-1],
:pw => url.scan(/:[A-Za-z0-9]+@/).first.gsub(/[^a-zA-Z0-9\-]/,""),
:host => url.scan(/(?<=@)(.*)(?=:)/).first.first,
pwData = url.scan(/:[A-Za-z0-9]+@/).first
hostData = url.scan(/(?<=@)(.*)(?=:)/).first
user = (url.scan(/postgres:..[A-Za-z0-9]+/).first.split('//') - ['localhost', 'postgres:']).first

{ :user => user,
:port => url.scan(/:[0-9]+./).first.split('/').first.gsub(/[^a-zA-Z0-9\-]/,""),
:dbname => url.scan(/.[A-Za-z0-9]+$/).first.gsub(/[^a-zA-Z0-9\-]/,"")
:dbname => url.scan(/.[A-Za-z0-9]+$/).first.gsub(/[^a-zA-Z0-9\-]/,""),
:host => hostData ? hostData.first : 'localhost',
:pw => pwData ? pwData.gsub(/[^a-zA-Z0-9\-]/,"") : nil
}
end

Expand Down

0 comments on commit 27aed86

Please sign in to comment.