-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support visualisation of Gems and its dependencies
- Loading branch information
1 parent
1bce087
commit 7443789
Showing
7 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
module RailsGraph | ||
module Commands | ||
module Builders | ||
class GemsBuilder | ||
def self.enrich(graph:, configuration:) | ||
return unless configuration.gems? | ||
|
||
new(graph: graph).enrich | ||
|
||
graph | ||
end | ||
|
||
def enrich | ||
build_gems_nodes | ||
|
||
gems.each do |specifications| | ||
source_node = graph.node("gem_#{specifications.name}") | ||
|
||
# build_authored_by_relationships(specifications, source_node) | ||
build_depends_on_gem_relationships(specifications, source_node) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :graph | ||
|
||
def initialize(graph:) | ||
@graph = graph | ||
end | ||
|
||
def build_gems_nodes | ||
gems.each do |gem| | ||
node = RailsGraph::Graph::Nodes::Gem.new(gem) | ||
graph.add_node(node) | ||
end | ||
end | ||
|
||
# def build_authored_by_relationships(specifications); end | ||
|
||
def build_depends_on_gem_relationships(specifications, source_node) | ||
specifications.dependencies.each do |dependency| | ||
target_node = graph.node("gem_#{dependency.name}") | ||
add_depends_on_gem_relationship(source_node, target_node, dependency) | ||
end | ||
end | ||
|
||
def add_depends_on_gem_relationship(source_node, target_node, dependency) | ||
relationship = RailsGraph::Graph::Relationship.new( | ||
source: source_node, | ||
target: target_node, | ||
label: "DependsOnGem", | ||
name: "depends_on_gem", | ||
properties: { type: dependency.type, requirement: dependency.requirement.to_s } | ||
) | ||
|
||
graph.add_relationship(relationship) | ||
end | ||
|
||
def gems | ||
@gems ||= Gem::Specification.all | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../node" | ||
|
||
module RailsGraph | ||
module Graph | ||
module Nodes | ||
class Gem < Node | ||
attr_reader :specifications | ||
|
||
def initialize(specifications) | ||
@specifications = specifications | ||
|
||
super(labels: "Gem", name: specifications.name, properties: build_properties) | ||
end | ||
|
||
def identifier | ||
"gem_#{name}" | ||
end | ||
|
||
private | ||
|
||
def build_properties | ||
{ | ||
description: specifications.description, | ||
summary: specifications.summary, | ||
homepage: specifications.homepage, | ||
version: specifications.version.to_s, | ||
licenses: specifications.licenses | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |