Class: MotionBlender::Analyzer
- Inherits:
-
Object
- Object
- MotionBlender::Analyzer
- Defined in:
- lib/motion_blender/analyzer.rb,
lib/motion_blender/analyzer/cache.rb,
lib/motion_blender/analyzer/parser.rb,
lib/motion_blender/analyzer/evaluator.rb
Defined Under Namespace
Classes: Cache, Evaluator, Parser
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #analyze(file, backtrace = []) ⇒ Object
-
#initialize ⇒ Analyzer
constructor
A new instance of Analyzer.
- #merge(parser) ⇒ Object
- #parse(file, backtrace) ⇒ Object
- #pick_autoloads(parser) ⇒ Object
Constructor Details
#initialize ⇒ Analyzer
Returns a new instance of Analyzer.
10 11 12 13 14 15 16 |
# File 'lib/motion_blender/analyzer.rb', line 10 def initialize @analyzed_files = Set.new @files = [] @dependencies = {} @autoloads = {} @file_stack = [] end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
8 9 10 |
# File 'lib/motion_blender/analyzer.rb', line 8 def dependencies @dependencies end |
#files ⇒ Object (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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/motion_blender/analyzer.rb', line 18 def analyze file, backtrace = [] @file_stack.push file return if MotionBlender.config.excepted_files.include? file return if @analyzed_files.include? file @analyzed_files << file parser = parse file, backtrace requires = merge parser requires.each do |req| req.run_callbacks :require do analyze req.file, [req.trace, *backtrace] end end ensure @file_stack.pop end |
#merge(parser) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/motion_blender/analyzer.rb', line 43 def merge parser pick_autoloads parser reqs = parser.dependent_requires(autoloads: @autoloads) reqs = reqs.reject { |req| @file_stack.include? req.file } if reqs.present? files = reqs.map(&:file) @dependencies[parser.file] = files @files = [*@files, parser.file, *files].uniq reqs else [] end end |
#parse(file, backtrace) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/motion_blender/analyzer.rb', line 58 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 end |
#pick_autoloads(parser) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/motion_blender/analyzer.rb', line 36 def pick_autoloads parser parser.requires.select(&:autoload?).each do |req| @autoloads[req.autoload_const_name] ||= [] @autoloads[req.autoload_const_name] << req end end |