Class: Puppet::Settings::FileOrDirectorySetting

Inherits:
FileSetting show all
Defined in:
lib/puppet/settings/file_or_directory_setting.rb

Instance Attribute Summary

Attributes inherited from FileSetting

#create, #mode

Attributes inherited from BaseSetting

#call_hook, #default, #deprecated, #desc, #name, #section, #short

Instance Method Summary collapse

Methods inherited from FileSetting

#create_files?, #exclusive_open, #group, #group=, #open, #owner, #owner=, #set_meta, #to_resource, #validate

Methods inherited from StringSetting

#validate

Methods inherited from BaseSetting

#allowed_on_commandline?, available_call_hook_values, #call_hook_on_define?, #call_hook_on_initialize?, #completely_deprecated?, #deprecated?, #getopt_args, #has_hook?, #hook=, #inspect, #iscreated, #iscreated?, #optparse_args, #print, #set_meta, #to_config, #value

Constructor Details

#initialize(args) ⇒ FileOrDirectorySetting


3
4
5
# File 'lib/puppet/settings/file_or_directory_setting.rb', line 3

def initialize(args)
  super
end

Instance Method Details

#munge(value) ⇒ Object

Overrides munge to be able to read the un-munged value (the FileSetting.munch removes trailing slash)


17
18
19
20
21
22
# File 'lib/puppet/settings/file_or_directory_setting.rb', line 17

def munge(value)
  if value.is_a?(String) && value =~ /[\\\/]$/
    @path_ends_with_slash = true
  end
  super
end

#open_file(filename, option = 'r', &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


31
32
33
34
35
36
37
38
39
# File 'lib/puppet/settings/file_or_directory_setting.rb', line 31

def open_file(filename, option = 'r', &block)
  if type == :file
    super
  else
    controlled_access do |mode|
      Puppet::FileSystem.open(filename, mode, option, &block)
    end
  end
end

#typeObject


7
8
9
10
11
12
13
# File 'lib/puppet/settings/file_or_directory_setting.rb', line 7

def type
  if Puppet::FileSystem.directory?(self.value) || @path_ends_with_slash
    :directory
  else
    :file
  end
end