Sha256: d20b96dd1e1afdad52f2ec5d30eb26228fa3b5ce12aa828c25996ca71f8a6c2d

Contents?: true

Size: 1.59 KB

Versions: 43

Compression:

Stored size: 1.59 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}"
			  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 }
			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

43 entries across 43 versions & 1 rubygems

Version Path
dev-1.0.193 lib/dev/cmd/Replace.rb
dev-1.0.192 lib/dev/cmd/Replace.rb
dev-1.0.191 lib/dev/cmd/Replace.rb
dev-1.0.190 lib/dev/cmd/Replace.rb
dev-1.0.189 lib/dev/cmd/Replace.rb
dev-1.0.188 lib/dev/cmd/Replace.rb
dev-1.0.187 lib/dev/cmd/Replace.rb
dev-1.0.186 lib/dev/cmd/Replace.rb
dev-1.0.185 lib/dev/cmd/Replace.rb
dev-1.0.184 lib/dev/cmd/Replace.rb
dev-1.0.182 lib/dev/cmd/Replace.rb
dev-1.0.181 lib/dev/cmd/Replace.rb
dev-1.0.180 lib/dev/cmd/Replace.rb
dev-1.0.179 lib/dev/cmd/Replace.rb
dev-1.0.178 lib/dev/cmd/Replace.rb
dev-1.0.177 lib/dev/cmd/Replace.rb
dev-1.0.176 lib/dev/cmd/Replace.rb
dev-1.0.175 lib/dev/cmd/Replace.rb
dev-1.0.174 lib/dev/cmd/Replace.rb
dev-1.0.173 lib/dev/cmd/Replace.rb