Class: Inspec::RelativeFileProvider
- Inherits:
- 
      Object
      
        - Object
- Inspec::RelativeFileProvider
 
- Defined in:
- lib/inspec/file_provider.rb
Overview
class TarProvider
Constant Summary collapse
- BLACKLIST_FILES =
- [ "/pax_global_header", "pax_global_header", ].freeze 
Instance Attribute Summary collapse
- 
  
    
      #files  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute files. 
- 
  
    
      #parent  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute parent. 
- 
  
    
      #prefix  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute prefix. 
Instance Method Summary collapse
- #abs_path(file) ⇒ Object
- #binread(file) ⇒ Object
- 
  
    
      #initialize(parent_provider)  ⇒ RelativeFileProvider 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of RelativeFileProvider. 
- #read(file) ⇒ Object
Constructor Details
#initialize(parent_provider) ⇒ RelativeFileProvider
Returns a new instance of RelativeFileProvider.
| 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | # File 'lib/inspec/file_provider.rb', line 221 def initialize(parent_provider) @parent = parent_provider @prefix = get_prefix(parent.files) if @prefix.nil? raise "Could not determine path prefix for #{parent}" end # select all files that begin with the prefix, and strip off the prefix from the file. # # strip off any leading top-level relative path (./) which is common in # PAX-formatted tar files. Do not do any translation of the path if the # path is an absolute path. @files = parent.files .find_all { |x| x.start_with?(prefix) && x != prefix } .map { |x| x[prefix.length..-1] } .map do |x| path = Pathname.new(x) path.absolute? ? path.to_s : path.relative_path_from(Pathname.new(".")).to_s end end | 
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
| 217 218 219 | # File 'lib/inspec/file_provider.rb', line 217 def files @files end | 
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
| 219 220 221 | # File 'lib/inspec/file_provider.rb', line 219 def parent @parent end | 
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
| 218 219 220 | # File 'lib/inspec/file_provider.rb', line 218 def prefix @prefix end | 
Instance Method Details
#abs_path(file) ⇒ Object
| 242 243 244 245 246 | # File 'lib/inspec/file_provider.rb', line 242 def abs_path(file) return nil if file.nil? prefix + file end | 
#binread(file) ⇒ Object
| 252 253 254 | # File 'lib/inspec/file_provider.rb', line 252 def binread(file) parent.binread(abs_path(file)) end | 
#read(file) ⇒ Object
| 248 249 250 | # File 'lib/inspec/file_provider.rb', line 248 def read(file) parent.read(abs_path(file)) end |