lib/pushwagner/environment.rb in pushwagner-0.0.1.2 vs lib/pushwagner/environment.rb in pushwagner-0.0.1.3
- old
+ new
@@ -9,11 +9,12 @@
attr_accessor :current, :version
def initialize(opts = {})
opts = HashWithIndifferentAccess.new(opts)
- config_file = opts[:config_file] || File.join(File.dirname(__FILE__), '/config/deploy.yml')
+ config_file = look_for_config_file(opts[:config_file])
+
@version = opts[:version] && opts[:version].to_s
@current = opts[:environment] || 'development'
@config = HashWithIndifferentAccess.new(YAML::load_file(config_file) || {})
end
@@ -50,8 +51,20 @@
environment['hosts'] || []
end
def user
environment['user'] || "nobody"
+ end
+
+ private
+ def look_for_config_file(file)
+ locations = [file, './deploy.yml', './.pw.yml', './config/deploy.yml']
+
+ locations.each do |location|
+ return location if File.exist? location
+ cf = File.join(File.dirname(__FILE__), location) # i.e rake/thor.
+ return cf if File.exist? cf
+ end
+ raise "Couldn't find config file in locations: #{locations.join(', ')}"
end
end
end
\ No newline at end of file