Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions lib/tapioca/gem/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def initialize(
@events = [] #: Array[Gem::Event]

@payload_symbols = Static::SymbolLoader.payload_symbols #: Set[String]
@bootstrap_symbols = load_bootstrap_symbols(@gem) #: Set[String]
gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) if include_doc
gem_graph = Static::SymbolLoader.graph_from_paths(@gem.files) #: Rubydex::Graph
gem_symbols = Static::SymbolLoader.symbols_from_graph(gem_graph)
engine_symbols = Static::SymbolLoader.engine_symbols(@gem)
@bootstrap_symbols = gem_symbols.union(engine_symbols) #: Set[String]

@bootstrap_symbols.each { |symbol| push_symbol(symbol) }

Expand Down Expand Up @@ -191,14 +193,6 @@ def name_of(constant)

private

#: (Gemfile::GemSpec gem) -> Set[String]
def load_bootstrap_symbols(gem)
engine_symbols = Static::SymbolLoader.engine_symbols(gem)
gem_symbols = Static::SymbolLoader.gem_symbols(gem)

gem_symbols.union(engine_symbols)
end

# Events handling

#: -> Gem::Event
Expand Down
12 changes: 8 additions & 4 deletions lib/tapioca/static/symbol_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ def graph_from_paths(paths)
graph
end

#: (Gemfile::GemSpec gem) -> Set[String]
def gem_symbols(gem)
symbols_from_paths(gem.files)
#: (Rubydex::Graph graph) -> Set[String]
def symbols_from_graph(graph)
namespaces = graph.declarations.grep(Rubydex::Namespace).map(&:name)
constants = graph.declarations.grep(Rubydex::Constant).map(&:name)
aliases = graph.declarations.grep(Rubydex::ConstantAlias).map(&:name)
(namespaces + constants + aliases).to_set
Comment on lines +31 to +34
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we're separating 3 collections just to immediately merge them back. How about something like this?

Suggested change
namespaces = graph.declarations.grep(Rubydex::Namespace).map(&:name)
constants = graph.declarations.grep(Rubydex::Constant).map(&:name)
aliases = graph.declarations.grep(Rubydex::ConstantAlias).map(&:name)
(namespaces + constants + aliases).to_set
graph.declarations.select do |decl|
decl.is_a?(Rubydex::Namespace) ||
decl.is_a?(Rubydex::Constant) ||
decl.is_a?(Rubydex::ConstantAlias)
end
end.to_set

end

#: (Gemfile::GemSpec gem) -> Set[String]
Expand All @@ -51,7 +54,8 @@ def engine_symbols(gem)
Pathname.glob("#{load_path}/**/*.rb")
end

symbols_from_paths(paths)
engine_graph = graph_from_paths(paths)
symbols_from_graph(engine_graph)
rescue
Set.new
end
Expand Down
Loading