Class: Referral::ScansTokens

Inherits:
Object
  • Object
show all
Defined in:
lib/referral/scans_tokens.rb

Instance Method Summary collapse

Constructor Details

#initializeScansTokens

Returns a new instance of ScansTokens.



7
8
9
10
11
# File 'lib/referral/scans_tokens.rb', line 7

def initialize
  @expands_directories = ExpandsDirectories.new
  @translates_node_to_token = TranslatesNodeToToken.new
  @tokenizes_identifiers = TokenizesIdentifiers.new
end

Instance Method Details

#call(files:, &blk) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/referral/scans_tokens.rb', line 13

def call(files:, &blk)
  @expands_directories.call(files).flat_map { |file|
    begin
      root = RubyVM::AbstractSyntaxTree.parse_file(file)
      find_tokens([root], nil, file)
    rescue SyntaxError => e
      warn "ERROR: Failed to parse \"#{file}\": #{e.message} (#{e.class})"
    rescue SystemCallError => e
      warn "ERROR: Failed to read \"#{file}\": #{e.message} (#{e.class})"
    end
  }.compact
end