Sha256: 0b9b2944415b3ebd797bef846e623ec0c6fd173d0219e194c71b94fe18810e59
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
require 'fileutils' module Analyst class Parser extend Forwardable def_delegators :root, :classes, :top_level_classes, :constants, :methods def self.for_files(*path_to_files) file_paths = path_to_files.map do |path| if File.directory?(path) Dir.glob(File.join(path, "**", "*.rb")) else path end end.flatten wrapped_asts = file_paths.map do |path| ast = ::Parser::CurrentRuby.parse(File.open(path, 'r').read) ::Parser::AST::Node.new(:analyst_file, [ast]) end root_node = ::Parser::AST::Node.new(:analyst_root, wrapped_asts) root = Entities::Root.new(root_node, file_paths) new(root) end def self.for_source(source) ast = ::Parser::CurrentRuby.parse(source) wrapped_ast = ::Parser::AST::Node.new(:analyst_source, [ast]) root_node = ::Parser::AST::Node.new(:analyst_root, [wrapped_ast]) root = Entities::Root.new(root_node, [source]) new(root) end def initialize(root) @root = root end def inspect "\#<#{self.class}:#{object_id}>" end def top_level_entities root.contents end private attr_reader :root end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
analyst-0.16.1 | lib/analyst/parser.rb |