Method: Fast.ast_from_file

Defined in:
lib/fast.rb

.ast_from_file(file) ⇒ Fast::Node

caches the content based on the filename. Also, it can parse SQL files.

Examples:

Fast.ast_from_file("example.rb") # => s(...)

Returns:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/fast.rb', line 154

def ast_from_file(file)
  @cache ||= {}
  @cache[file] ||=
    begin
      method =
        if file.end_with?('.sql')
          require_relative 'fast/sql' unless respond_to?(:parse_sql)
          :parse_sql
        else
          :ast
        end
      Fast.public_send(method, IO.read(file), buffer_name: file)
    end
end