-
Notifications
You must be signed in to change notification settings - Fork 0
/
gem-list.rb
73 lines (61 loc) · 2.43 KB
/
gem-list.rb
1
2
3
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
67
68
69
70
71
72
73
#This gives out the list of dependencies that are not necessary and prints all of the in the 'dependency_status.json' file
#by specifying if they are required or not. It firsts checks if there was any gems that were run in the past (in the json file) and
#then continues from there.
require 'json'
class Dependencies
class << self
def list_of_dependencies()
File.open('../periodic-pigeon/Gemfile') do |file|
file.each_line
.select { |line| line.start_with?("gem") }
.map { |line| line.split[1].tr("',", "") }
end
end
def reset(dependencies)
Dir.chdir("../periodic-pigeon")
`git reset --hard && bundle install`
end
def load_statuses
if File.exists?('dependency_status.json')
json =File.read('dependency_status.json')
JSON.parse(json)
else
{}
end
end
def unload_statuses(statuses)
json= JSON.unparse(statuses) #generate json string from the hash
File.write('dependency_status.json', json) # hashes to file
end
def test_method(dependencies)
Dir.chdir("../periodic-pigeon")
output =`git status --porcelain --untracked-files=no`
unless output.empty?
puts "File was modified after previous commit"
return
end
statuses = load_statuses
dependencies.each do |dependency|
if statuses.key?(dependency)
puts "skipping #{dependency}"
next
end
puts "removing #{dependency}"
`bundle remove #{dependency}`
`bundle clean --force` #This command cleans up all unnecessary dependencies!
puts "running tests"
`rails test`
statuses[dependency]=($?.exitstatus != 0) #false means safe to go
unload_statuses(statuses)
puts "reseting"
`git reset --hard && bundle install`
end
statuses.select{|k, v| !v}.keys
end
end
end
dependencies =Dependencies.list_of_dependencies()
unnecessary =Dependencies.test_method(dependencies)
puts "These dependencies are not necessary"
unnecessary.each {|u| puts "- #{u}"}
# Dependencies.reset(dependencies)