Class: Dev::Cmd::Replace

Inherits:
Hash
  • Object
show all
Defined in:
lib/dev/cmd/Replace.rb

Instance Method Summary collapse

Methods inherited from Hash

get_hash_value, #get_value, print_hash, set_hash_value, #set_value, #strip_auto_entries

Instance Method Details

#executeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dev/cmd/Replace.rb', line 43

def execute
  self.each do |k,v| 
	unless v.nil?
file=v[:file]
search=v[:search]
replace=v[:replace]
glob=v[:glob]
unless search.nil? || replace.nil?
unless file.nil?
	Dev::Environment.replace_text_in_file(file,search,replace)
end
unless glob.nil?
	Dev::Environment.replace_text_in_glob(glob,search,replace)
end
end
	end
  end
end

#refresh(dep_hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dev/cmd/Replace.rb', line 4

def refresh(dep_hash)
  puts_debug "Dev::Cmd::Replace.refresh"
  # remove all auto generated entries
	self.each { |k,v|
 self.delete k if v.kind_of?(Hash) && v.has_key?(:auto) && v[:auto] 
	}

	# auto generate replace entry based on dep values
	if File.exists?(".svn") || File.exists?(".git")
 ["vcxproj","csproj"].each { |ext|
   if(Dir.glob("**/*.#{ext}").count > 0)
  puts_debug "Dev::Cmd::Replace.refresh found file with extension #{ext}"
  puts_debug "dep_hash nil" if dep_hash.nil?
  puts_debug "dep_hash is empty" if dep_hash.empty?
  dep_hash.each{ |k,v|
    puts_debug "Dev::Cmd::Replace.refresh found dep of key #{k.to_s}"
    if !v.nil? && v.kind_of?(Hash) && v.has_key?(:rev) && v.has_key?(:dir) && !has_key?(k)
	  puts_debug "adding key #{k.to_s}"
	  if(v[:dir].include?('@'))
	    words=v[:dir].split('@')
		parts=words[0].split('/');
		searchRegex=Regexp.new "#{parts[0]}\\\\#{parts[1]}\\\\#{parts[2]}@[\\d]+"
		#searchRegex=Regexp.new "#{words[0].gsub('/','\\\\')}@[\\d]+"
	    self[k]={ glob: "**/*.#{ext}", search: searchRegex, replace: "#{words[0].gsub('/','\\')}@#{v[:rev]}", auto: true }
	  else
	    group=v[:dir].split('/')[0]
	    name=v[:dir].split('/')[1]
	    searchRegex=Regexp.new "#{group}\\\\#{name}\\\\[\\d]+"
	    self[k]={ glob: "**/*.#{ext}", search: searchRegex, replace: "#{group}\\#{name}\\#{v[:rev]}", auto: true }
	  end
	else
	  puts_debug "skipping key #{k.to_s}"
	end
  }
end
 }
	end
end