Class: MotionBlender::Analyzer::Require
- Inherits:
-
Object
- Object
- MotionBlender::Analyzer::Require
- Includes:
- ActiveSupport::Callbacks
- Defined in:
- lib/motion_blender/analyzer/require.rb
Constant Summary collapse
- TOKENS =
i(motion_require require_relative require)
Instance Attribute Summary collapse
-
#arg ⇒ Object
Returns the value of attribute arg.
-
#loader ⇒ Object
Returns the value of attribute loader.
-
#method ⇒ Object
Returns the value of attribute method.
-
#trace ⇒ Object
Returns the value of attribute trace.
Class Method Summary collapse
Instance Method Summary collapse
- #candidates ⇒ Object
- #excluded? ⇒ Boolean
- #explicit_relative(path) ⇒ Object
- #file ⇒ Object
-
#initialize(loader, method, arg) ⇒ Require
constructor
A new instance of Require.
- #load_path ⇒ Object
- #match?(arg_or_file) ⇒ Boolean
- #resolve_path ⇒ Object
- #uses_load_path? ⇒ Boolean
Constructor Details
#initialize(loader, method, arg) ⇒ Require
Returns a new instance of Require.
14 15 16 17 18 |
# File 'lib/motion_blender/analyzer/require.rb', line 14 def initialize loader, method, arg @loader = loader @method = method @arg = arg end |
Instance Attribute Details
#arg ⇒ Object
Returns the value of attribute arg.
12 13 14 |
# File 'lib/motion_blender/analyzer/require.rb', line 12 def arg @arg end |
#loader ⇒ Object
Returns the value of attribute loader.
12 13 14 |
# File 'lib/motion_blender/analyzer/require.rb', line 12 def loader @loader end |
#method ⇒ Object
Returns the value of attribute method.
12 13 14 |
# File 'lib/motion_blender/analyzer/require.rb', line 12 def method @method end |
#trace ⇒ Object
Returns the value of attribute trace.
12 13 14 |
# File 'lib/motion_blender/analyzer/require.rb', line 12 def trace @trace end |
Class Method Details
.acceptable?(method) ⇒ Boolean
70 71 72 |
# File 'lib/motion_blender/analyzer/require.rb', line 70 def self.acceptable? method TOKENS.include?(method) end |
Instance Method Details
#candidates ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/motion_blender/analyzer/require.rb', line 30 def candidates path = if i(motion_require require_relative).include? method Pathname.new(loader).dirname.join(arg) else Pathname.new(arg) end dirs = path.relative? && load_path || [''] exts = path.extname.empty? ? ['', '.rb'] : [''] Enumerator.new do |y| dirs.product(exts).each do |dir, ext| y << Pathname.new(dir).join("#{path}#{ext}") end end end |
#excluded? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/motion_blender/analyzer/require.rb', line 64 def excluded? MotionBlender.config.builtin_features.include?(arg) || MotionBlender.config.excepted_files.include?(arg) || MotionBlender.config.excepted_files.include?(file) end |
#explicit_relative(path) ⇒ Object
46 47 48 |
# File 'lib/motion_blender/analyzer/require.rb', line 46 def explicit_relative path path.to_s.sub(%r{^(?![\./])}, './') end |
#file ⇒ Object
20 21 22 |
# File 'lib/motion_blender/analyzer/require.rb', line 20 def file @file ||= resolve_path end |
#load_path ⇒ Object
54 55 56 57 58 |
# File 'lib/motion_blender/analyzer/require.rb', line 54 def load_path if uses_load_path? MotionBlender.config.motion_dirs + $LOAD_PATH end end |
#match?(arg_or_file) ⇒ Boolean
60 61 62 |
# File 'lib/motion_blender/analyzer/require.rb', line 60 def match? arg_or_file arg == arg_or_file || file == arg_or_file end |
#resolve_path ⇒ Object
24 25 26 27 28 |
# File 'lib/motion_blender/analyzer/require.rb', line 24 def resolve_path path = candidates.find(&:file?) fail LoadError, "not found `#{arg}'" unless path explicit_relative path end |
#uses_load_path? ⇒ Boolean
50 51 52 |
# File 'lib/motion_blender/analyzer/require.rb', line 50 def uses_load_path? method == :require end |