Sha256: a78f9c267e3928a3bc99c9c57be867bef6bf5c0f6cdd62ec02ccb4daf6340081

Contents?: true

Size: 1.97 KB

Versions: 21

Compression:

Stored size: 1.97 KB

Contents

module Dev
module Cmd
class Replace < Hash
  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

  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

end # class Replace
end # module Cmd
end # module Dev

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
dev-1.0.214 lib/dev/cmd/Replace.rb
dev-1.0.213 lib/dev/cmd/Replace.rb
dev-1.0.212 lib/dev/cmd/Replace.rb
dev-1.0.211 lib/dev/cmd/Replace.rb
dev-1.0.210 lib/dev/cmd/Replace.rb
dev-1.0.209 lib/dev/cmd/Replace.rb
dev-1.0.208 lib/dev/cmd/Replace.rb
dev-1.0.207 lib/dev/cmd/Replace.rb
dev-1.0.206 lib/dev/cmd/Replace.rb
dev-1.0.205 lib/dev/cmd/Replace.rb
dev-1.0.204 lib/dev/cmd/Replace.rb
dev-1.0.203 lib/dev/cmd/Replace.rb
dev-1.0.202 lib/dev/cmd/Replace.rb
dev-1.0.201 lib/dev/cmd/Replace.rb
dev-1.0.200 lib/dev/cmd/Replace.rb
dev-1.0.199 lib/dev/cmd/Replace.rb
dev-1.0.198 lib/dev/cmd/Replace.rb
dev-1.0.197 lib/dev/cmd/Replace.rb
dev-1.0.196 lib/dev/cmd/Replace.rb
dev-1.0.195 lib/dev/cmd/Replace.rb