Class: MotionBlender::Analyzer::Require

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
lib/motion_blender/analyzer/require.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader, method, arg) ⇒ Require

Returns a new instance of Require.



12
13
14
15
16
# File 'lib/motion_blender/analyzer/require.rb', line 12

def initialize loader, method, arg
  @loader = loader
  @method = method
  @arg = arg
end

Instance Attribute Details

#argObject

Returns the value of attribute arg.



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

def arg
  @arg
end

#loaderObject

Returns the value of attribute loader.



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

def loader
  @loader
end

#methodObject

Returns the value of attribute method.



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

def method
  @method
end

#traceObject

Returns the value of attribute trace.



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

def trace
  @trace
end

Instance Method Details

#candidatesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/motion_blender/analyzer/require.rb', line 28

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

#explicit_relative(path) ⇒ Object



44
45
46
# File 'lib/motion_blender/analyzer/require.rb', line 44

def explicit_relative path
  path.to_s.sub(%r{^(?![\./])}, './')
end

#fileObject



18
19
20
# File 'lib/motion_blender/analyzer/require.rb', line 18

def file
  @file ||= resolve_path
end

#load_pathObject



52
53
54
55
56
# File 'lib/motion_blender/analyzer/require.rb', line 52

def load_path
  if uses_load_path?
    MotionBlender.config.motion_dirs + $LOAD_PATH
  end
end

#match?(arg_or_file) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/motion_blender/analyzer/require.rb', line 58

def match? arg_or_file
  arg == arg_or_file || file == arg_or_file
end

#resolve_pathObject



22
23
24
25
26
# File 'lib/motion_blender/analyzer/require.rb', line 22

def resolve_path
  path = candidates.find(&:file?)
  fail LoadError, "not found `#{arg}'" unless path
  explicit_relative path
end

#uses_load_path?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/motion_blender/analyzer/require.rb', line 48

def uses_load_path?
  method == :require
end