Top Level Namespace

Defined Under Namespace

Modules: ConstraintClean

Instance Method Summary collapse

Instance Method Details

#cleanupConstraints(file) ⇒ 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/constraintClean.rb', line 4

def cleanupConstraints(file)

	f = File.open(file)
	doc = Nokogiri::XML(f)
	f.close
	
	excluded = []
	variations = doc.xpath('//variation')
	
	included   = doc.xpath('//include')
	outlets    = doc.xpath('//outlet')
	
	variations.each do |variation|
		if variation.attr('key') == "default"
			ch = variation.children
			ch.each do |mask|
				constraints = mask.children
				constraints.each do |constraint|
					if constraint.name == 'exclude'
						excluded.push(constraint)
					end
				end 
			end
		end
	end
	
	result = [] 
	excluded.each do |node| 
		found = false
		for includedNode in included
		p node
			if node.attr('reference') == includedNode.attr('reference')
				found = true
				break
			end
		end
		
		if !found 
			for outlet in outlets
				if node.attr('reference') == outlet.attr('destination')
					found = true
					break
				end	
			end
		end 
		
		if !found 
			result.push(node)
			nodeID = node.attr('reference')
			constraints = doc.xpath("//constraint[@id='#{nodeID}']")
			result += constraints
		end
	end
	if result.count > 0 
		f1 = File.open(file, 'w')
		result.each{ |node| node.remove }
		content = doc.to_xml.each_line.reject{|x| x.strip == ""}.join
		f1.write(content)	
		f1.close
		
		p "removed #{result.count} constraint(s) from #{file}"
	end
end

#notifyAboutUpdatesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/version_update.rb', line 5

def notifyAboutUpdates
	json_object = JSON.parse(open("https://rubygems.org/api/v1/versions/constraintClean/latest.json").read)
    highest_version = Gem.loaded_specs['constraintClean'].version.to_s
	if json_object["version"].nil?
		return 
	end
	if json_object["version"] > highest_version 
		puts "Updates are available!".green
		puts "Your current version of constraintClean is #{highest_version}".green
		puts "Run 'gem update constraintClean' to get latest version #{json_object['version']}".green
		puts ""
	end      
end