Sha256: d945739ed4fecfc1e3f491374cac99f6e2147b838ea68f2147c9d634567a7955

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 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)
		  dep_hash.each{ |k,v|
		    if !v.nil? && v.kind_of?(Hash) && v.has_key?(:rev) && v.has_key?(:dir) && !has_key?(k)
			  group=v[:dir].split('/')[0]
			  searchRegex=Regexp.new "#{group}\\\\#{k}\\\\[\\d]+"
			  self[k]={ glob: "**/*.#{ext}", search: searchRegex, replace: "#{group}\\#{k}\\#{v[:rev]}", auto: true }
			  #self[k][:auto]=true
			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

2 entries across 2 versions & 1 rubygems

Version Path
dev-1.0.148 lib/dev/cmd/Replace.rb
dev-1.0.147 lib/dev/cmd/Replace.rb