Module: InspecPlugins::FlexReporter::FileResolver
- Included in:
- Reporter
- Defined in:
- lib/inspec-reporter-flex/mixin/file_resolver.rb
Instance Method Summary collapse
-
#absolute_path?(name) ⇒ Boolean
Is this an absolute path?.
-
#gem_path(name) ⇒ String
Return absolute path for a file bundled with this Gem.
-
#gem_path?(name) ⇒ Boolean
Is this a Gem-bundled path?.
-
#relative_path(name) ⇒ String
Return absolute path for a file relative to Dir.pwd.
-
#relative_path?(name) ⇒ Boolean
Is this an relative path?.
-
#resolve_path(name) ⇒ String
Resolve the absolute path for a file in order absolute path/gem bundled file/relative.
Instance Method Details
#absolute_path?(name) ⇒ Boolean
Is this 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.
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?
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.
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?
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.
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 |