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
|
# File 'lib/gemgrapher.rb', line 15
def initialize
@content = content(File.read("Gemfile"))
@gemfile ||= Gemnasium::Parser::Gemfile.new(@content)
deps = {}
point = {}
p @gemfile.dependencies
total = @gemfile.dependencies.length
@data = []
count = 0
@gemfile.dependencies.each do |g|
response = open("http://rubygems.org/api/v1/gems/#{g.name}.json").read
parsed_json = JSON.parse(response)
dependencies = parsed_json["dependencies"]["runtime"].to_a
deps["#{g.name}"] = dependencies.map{|d| deps["#{d['name']}"] ||= [] ;d["name"]}
p "#{count+=1} out of #{total} "
end
deps.each do |key, value|
@data << {"name" => "root.#{key}", "imports" => value.map{|v| "root.#{v}"}}
end
data = File.read(gem_libdir + "/assets/index.html")
filtered_data = data.gsub("classes = JSON.parse()", "classes = JSON.parse('#{@data.to_json}')")
File.open("index.html", "w") do |f|
f.write(filtered_data)
end
end
|