Class: MotionBlender::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_blender/analyzer.rb,
lib/motion_blender/analyzer/cache.rb,
lib/motion_blender/analyzer/parser.rb,
lib/motion_blender/analyzer/source.rb,
lib/motion_blender/analyzer/require.rb,
lib/motion_blender/analyzer/evaluator.rb,
lib/motion_blender/analyzer/original_finder.rb

Defined Under Namespace

Classes: Cache, Evaluator, OriginalFinder, Parser, Require, Source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAnalyzer

Returns a new instance of Analyzer.



10
11
12
13
14
# File 'lib/motion_blender/analyzer.rb', line 10

def initialize
  @analyzed_files = Set.new
  @files = []
  @dependencies = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/motion_blender/analyzer.rb', line 8

def cache
  @cache
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



8
9
10
# File 'lib/motion_blender/analyzer.rb', line 8

def dependencies
  @dependencies
end

#filesObject (readonly)

Returns the value of attribute files.



8
9
10
# File 'lib/motion_blender/analyzer.rb', line 8

def files
  @files
end

Instance Method Details

#analyze(file, backtrace = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/motion_blender/analyzer.rb', line 16

def analyze file, backtrace = []
  return if MotionBlender.config.excepted_files.include? file
  return if @analyzed_files.include? file
  @analyzed_files << file

  requires = parse file, backtrace

  if requires.present?
    @dependencies[file] = requires.map(&:file)
    @files = [*@files, file, *@dependencies[file]].uniq
    requires.each do |req|
      req.run_callbacks :require do
        analyze req.file, [req.trace, *backtrace]
      end
    end
  end
end

#parse(file, backtrace) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/motion_blender/analyzer.rb', line 34

def parse file, backtrace
  parser = Parser.new file
  begin
    parser.parse
  rescue LoadError => err
    err.set_backtrace [parser.last_trace, *backtrace].compact
    raise err
  end
  parser.requires
end