lib/dev/Environment.rb in dev-1.0.145 vs lib/dev/Environment.rb in dev-1.0.146
- old
+ new
@@ -78,10 +78,39 @@
machine = `hostname`
machine = machine.split('.')[0] if machine.include?('.')
return machine.strip
#return "unknown"
end
-
+ def self.expand_command(command); Dev::Environment.expand_project_variables(command); end
+ def self.expand_project_variables(str)
+ if str.kind_of?(Hash)
+ expandedHash = Hash.new
+ str.each do |name,value|
+ expandedHash[name]=expand_project_variables(value)
+ end
+ return expandedHash
+ end
+
+ if str.kind_of?(Array)
+ expandedArray= Array.new
+ str.each{|e|expandedArray << expand_project_variable(e) }
+ return expandedArray
+ end
+
+ if str.kind_of?(String)
+ result=Dev::Environment.expand_string_variables(str) # expands ruby variables, e.g. '#{name}' to 'widget'
+ if result.include?('<') && result.include?('>')
+ result.scan(/(<[\w,]+>)/).each { |pvar| # expand project variables, e.g. '<name>' to 'widget
+ key = pvar[0].gsub("<","").gsub(">","") # '<paths,nunit>' to 'C:/wherever/NUnit.exe'
+ value=DEV.get_value(key)
+ result = result.gsub(pvar[0],value)
+ }
+ end
+ return result
+ end
+
+ return str
+ end
end
end # module Dev