Module: InspecPlugins::FlexReporter::FileResolver

Included in:
Reporter
Defined in:
lib/inspec-reporter-flex/mixin/file_resolver.rb

Instance Method Summary collapse

Instance Method Details

#absolute_path?(name) ⇒ Boolean

Is this an absolute path?

Parameters:

  • name (String)

    name or path of a file

Returns:

  • (Boolean)

    if it is an absolute path



24
25
26
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 24

def absolute_path?(name)
  name.start_with? "/"
end

#gem_path(name) ⇒ String

Return absolute path for a file bundled with this Gem.

Parameters:

  • name (String)

    Name or path of a file

Returns:

  • (String)

    Absolute path to the file



56
57
58
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 56

def gem_path(name)
  File.join(__dir__, "../../..", name)
end

#gem_path?(name) ⇒ Boolean

Is this a Gem-bundled path?

Parameters:

  • name (String)

    name or path of a file

Returns:

  • (Boolean)

    if it is a Gem-bundled path



40
41
42
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 40

def gem_path?(name)
  File.exist? gem_path(name)
end

#relative_path(name) ⇒ String

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

Parameters:

  • name (String)

    Name or path of a file

Returns:

  • (String)

    Absolute path to the file



48
49
50
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 48

def relative_path(name)
  File.join(Dir.pwd, name)
end

#relative_path?(name) ⇒ Boolean

Is this an relative path?

Parameters:

  • name (String)

    name or path of a file

Returns:

  • (Boolean)

    if it is an relative path



32
33
34
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 32

def relative_path?(name)
  File.exist? relative_path(name)
end

#resolve_path(name) ⇒ String

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

Parameters:

  • name (String)

    Name or path of a file to resolve

Returns:

  • (String)

    Absolute path to the file, if any

Raises:

  • (RuntimeError)

    if file not found



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/inspec-reporter-flex/mixin/file_resolver.rb', line 8

def resolve_path(name)
  if absolute_path?(name)
    name
  elsif relative_path?(name)
    relative_path(name)
  elsif gem_path?(name)
    gem_path(name)
  else
    raise "Template file #{name} not found"
  end
end