Module: OverridesPermissions

Included in:
Target::Deb::DebianSourceWrapper
Defined in:
lib/gpm/source/files_providers/overrides_permissions.rb

Overview

This module is intended as a mixin, you still need to implement the respective methods, i.e. base_provider and permission_overrides

Instance Method Summary collapse

Instance Method Details

#file_contentsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gpm/source/files_providers/overrides_permissions.rb', line 7

def file_contents
  #Beware: Deep magic here.
  result = base_provider.file_contents.map do |file_with_permissions,content|
    _,override = permission_overrides.map do |condition,permission|
      # Find the length of the longest match for the current regexp.
      longest = file_with_permissions.scan(condition).map do |match|
        match = match.join if match.kind_of? Array
        match.length
      end.max
      # return the length of the longest match and the associated permission
      # or nil if there was no match
      [longest,permission] if longest
    end.compact.max_by(&:first) #Get the Array with the greatest length in the first component.
    file_with_permissions = FilePathAndPermissions.new(file_with_permissions,override) if override
    [file_with_permissions,content]
  end
  Hash[*result.flatten]
end

#filesObject



26
27
28
# File 'lib/gpm/source/files_providers/overrides_permissions.rb', line 26

def files
  file_contents.keys
end