class PuppetGenerator::ExportFilters::FilesystemAttributes

Public Instance Methods

convert(objects) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 4
def convert(objects)

  objects.collect do |o|
    path = o[:name]

    if File.exists? path
      fs_object_info = stats(path)

      o.merge!( { 
        type: type(path),
        owner: owner(fs_object_info),
        mode: mode(fs_object_info),
      } )
    end

    o
  end

end

Private Instance Methods

directory?(path) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 52
def directory?(path)
  FileTest.directory? path
end
file?(path) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 48
def file?(path)
  FileTest.file? path
end
mode(fs_object_info) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 30
def mode(fs_object_info)
  "%o" % fs_object_info.mode
end
owner(fs_object_info) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 34
def owner(fs_object_info)
  Etc.getpwuid(fs_object_info.uid).name
end
stats(path) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 26
def stats(path)
  File::Stat.new(path) 
end
type(path) click to toggle source
# File lib/puppet_generator/export_filters/filesystem_attributes.rb, line 38
def type(path)
  if file?(path)
    return 'file'
  elsif directory?(path)
    return 'directory'
  else
    return 'file'
  end
end