module InspecPlugins::FlexReporter::FileResolver

Public Instance Methods

absolute_path?(name) click to toggle source

Is this an absolute path?

@param [String] name name or path of a file @return [Boolean] if it is an absolute path

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 26
def absolute_path?(name)
  absolute_unix_path?(name) || absolute_windows_path?(name)
end
absolute_unix_path?(name) click to toggle source

Is this an absolute path on UNIX systems?

@param [String] name name or path of a file @return [Boolean] if it is an absolute path

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 34
def absolute_unix_path?(name)
  File.exist?(name) && name.start_with?("/")
end
absolute_windows_path?(name) click to toggle source

Is this an absolute path on Windows systems?

@param [String] name name or path of a file @return [Boolean] if it is an absolute path

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 42
def absolute_windows_path?(name)
  File.exist?(name) && name.match?(/^[a-zA-C]:/)
end
full_path(name) click to toggle source

Resolve the full path for a file in order absolute path/gem bundled file/relative.

@param [String] name Name or path of a file to resolve @return [String] Absolute path to the file, if any @raise [IOError] if file not found

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 10
def full_path(name)
  if absolute_path?(name)
    name
  elsif relative_path?(name)
    relative_path(name)
  elsif gem_path?(name)
    gem_path(name)
  else
    raise IOError, "Template file #{name} not found"
  end
end
gem_path(name) click to toggle source

Return absolute path for a file bundled with this Gem.

@param [String] name Name or path of a file @return [String] Absolute path to the file

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 74
def gem_path(name)
  File.join(__dir__, "../../..", name)
end
gem_path?(name) click to toggle source

Is this a Gem-bundled path?

@param [String] name name or path of a file @return [Boolean] if it is a Gem-bundled path

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 58
def gem_path?(name)
  File.exist? gem_path(name)
end
relative_path(name) click to toggle source

Return absolute path for a file relative to Dir.pwd.

@param [String] name Name or path of a file @return [String] Absolute path to the file

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 66
def relative_path(name)
  File.join(Dir.pwd, name)
end
relative_path?(name) click to toggle source

Is this an relative path?

@param [String] name name or path of a file @return [Boolean] if it is an relative path

# File lib/inspec-reporter-flex/mixin/file_resolver.rb, line 50
def relative_path?(name)
  File.exist? relative_path(name)
end