Class: Dev::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/dev/Environment.rb

Class Method Summary collapse

Class Method Details

.dev_rootObject



19
20
21
22
23
24
25
# File 'lib/dev/Environment.rb', line 19

def self.dev_root
  dir="~"
  dir=ENV["HOME"] unless ENV["HOME"].nil?
  dir=ENV["USERPROFILE"].gsub('\\','/') unless ENV["USERPROFILE"].nil?
  dir=ENV["DEV_ROOT"].gsub('\\','/') unless ENV["DEV_ROOT"].nil?
  return dir
end

.expand_string_variables(str) ⇒ Object



27
28
29
# File 'lib/dev/Environment.rb', line 27

def self.expand_string_variables(str)
  eval("\"#{str.gsub('"','\"')}\"")
end

.replace_text_in_file(filename, search, replace) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/dev/Environment.rb', line 10

def self.replace_text_in_file(filename,search,replace)
  text1 = File.read(filename)
  text2 = text1.gsub(search) { |str| str=replace }
  unless text1==text2
    File.open(filename,"w") { |f| f.puts text2 }
    puts "replaced text in #{filename}"
  end
end

.replace_text_in_glob(glob, search, replace) ⇒ Object



6
7
8
# File 'lib/dev/Environment.rb', line 6

def self.replace_text_in_glob(glob,search,replace)
  Dir.glob(glob).each{ |f| replace_text_in_file(f,search,replace) }
end

.s_to_hash(str) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dev/Environment.rb', line 31

def self.s_to_hash(str)
   # check for hash
   hash=nil
   if(str.strip.index('{')==0 && str.strip.index('}')==str.strip.length-1)
     begin
       eval("hash=#{str.strip}")
     rescue
       hash=nil
     end
   end
   hash
end