diff --git a/factory_bro.gemspec b/factory_bro.gemspec index 1eefdad..ff9bcf8 100644 --- a/factory_bro.gemspec +++ b/factory_bro.gemspec @@ -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"] diff --git a/lib/factory_bro.rb b/lib/factory_bro.rb index ed392f8..c3e0a9e 100644 --- a/lib/factory_bro.rb +++ b/lib/factory_bro.rb @@ -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