Class: RDI::Testers::RubyRequires

Inherits:
Model::Tester show all
Defined in:
lib/rdi/Plugins/Testers/RubyRequires.rb

Overview

Test that some Ruby files are accessible

Instance Attribute Summary

Attributes inherited from Model::Tester

#AffectingContextModifiers

Instance Method Summary collapse

Instance Method Details

#getAffectingContextModifiersObject

Give the name of possible ContextModifiers that might change the resolution of this Tester. This is used to know what context modifiers the user can use to resolve dependencies without having to install.

Return:

  • list<String>: The list of ContextModifiers names



21
22
23
# File 'lib/rdi/Plugins/Testers/RubyRequires.rb', line 21

def getAffectingContextModifiers
  return [ 'GemPath', 'RubyLoadPath' ]
end

#isContentResolved?(iContent) ⇒ Boolean

Test if a given content is resolved

Parameters:

  • iContent (Object): The tester’s content

Return:

  • Boolean: Is the content resolved ?

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rdi/Plugins/Testers/RubyRequires.rb', line 31

def isContentResolved?(iContent)
  # * *iContent* (<em>list<String></em>): The list of requires to resolve
  rSuccess = false

  # Handle RubyGems as an option
  if (defined?(Gem) == nil)
    # No RubyGem.
    # For each required file, test that it exists among $LOAD_PATH
    iContent.each do |iRequireName|
      lFileFilter = iRequireName
      if (File.extname(iRequireName).empty?)
        lFileFilter = "#{iRequireName}.{rb,so,o,sl,dll}"
      end
      rSuccess = false
      $LOAD_PATH.each do |iDir|
        rSuccess = (!Dir.glob(File.expand_path("#{iDir}/#{lFileFilter}")).empty?)
        if (rSuccess)
          # We found it. Don't try other paths.
          break
        end
      end
      if (!rSuccess)
        # We didn't find this require. Don't try other requires.
        break
      end
    end
  else
    # RubyGems is here. Use it.
    # For each required file, test that it exists among the RubyGems' loaded paths
    iContent.each do |iRequireName|
      rSuccess = (!Gem.find_files(iRequireName).empty?)
      if (!rSuccess)
        # We did not find this one: don't even try the next ones
        break
      end
    end
  end

  return rSuccess
end