Class: Inspec::Plugins::RelFetcher

Inherits:
Fetcher show all
Defined in:
lib/inspec/plugins/fetcher.rb

Instance Attribute Summary collapse

Attributes inherited from PluginRegistry::Plugin

#parent, #target

Instance Method Summary collapse

Methods inherited from Fetcher

plugin_registry, #relative_target

Methods inherited from PluginRegistry::Plugin

name, plugin_registry, priority, resolve, resolve_next

Constructor Details

#initialize(fetcher) ⇒ RelFetcher

Returns a new instance of RelFetcher.



44
45
46
47
48
49
# File 'lib/inspec/plugins/fetcher.rb', line 44

def initialize(fetcher)
  @parent = fetcher
  @prefix = get_prefix(fetcher.files)
  @files = fetcher.files.find_all { |x| x.start_with? prefix }
                  .map { |x| x[prefix.length..-1] }
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



41
42
43
# File 'lib/inspec/plugins/fetcher.rb', line 41

def files
  @files
end

#prefixObject (readonly)

Returns the value of attribute prefix.



42
43
44
# File 'lib/inspec/plugins/fetcher.rb', line 42

def prefix
  @prefix
end

Instance Method Details

#abs_path(file) ⇒ Object



51
52
53
54
# File 'lib/inspec/plugins/fetcher.rb', line 51

def abs_path(file)
  return nil if file.nil?
  prefix + file
end

#read(file) ⇒ Object



56
57
58
# File 'lib/inspec/plugins/fetcher.rb', line 56

def read(file)
  @parent.read(abs_path(file))
end