Class: Puppet::FileServing::Metadata
Overview
A class that handles retrieving file metadata.
Constant Summary collapse
- PARAM_ORDER =
[:mode, :ftype, :owner, :group]
Instance Attribute Summary collapse
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#checksum_type ⇒ Object
Returns the value of attribute checksum_type.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#ftype ⇒ Object
readonly
Returns the value of attribute ftype.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Base
#links, #relative_path, #source
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_with_tabs ⇒ Object
-
#collect ⇒ Object
Retrieve the attributes for this file, relative to a base directory.
-
#initialize(path, data = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #to_pson(*args) ⇒ Object
- #to_pson_data_hash ⇒ Object
Methods included from Indirector
Methods included from Util::Checksums
#checksum?, #ctime, #ctime_file, #md5, #md5_file, #md5_stream, #md5lite, #md5lite_file, #mtime, #mtime_file, #mtime_stream, #none, #none_file, #none_stream, #sha1, #sha1_file, #sha1_stream, #sha1lite, #sha1lite_file, #sumdata, #sumtype
Methods inherited from Base
Constructor Details
#initialize(path, data = {}) ⇒ Metadata
Returns a new instance of Metadata.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puppet/file_serving/metadata.rb', line 72 def initialize(path,data={}) @owner = data.delete('owner') @group = data.delete('group') @mode = data.delete('mode') if checksum = data.delete('checksum') @checksum_type = checksum['type'] @checksum = checksum['value'] end @checksum_type ||= "md5" @ftype = data.delete('type') @destination = data.delete('destination') super(path,data) end |
Instance Attribute Details
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def checksum @checksum end |
#checksum_type ⇒ Object
Returns the value of attribute checksum_type.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def checksum_type @checksum_type end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def destination @destination end |
#ftype ⇒ Object (readonly)
Returns the value of attribute ftype.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def ftype @ftype end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def group @group end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def mode @mode end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def owner @owner end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/puppet/file_serving/metadata.rb', line 20 def path @path end |
Class Method Details
.from_pson(data) ⇒ Object
114 115 116 |
# File 'lib/puppet/file_serving/metadata.rb', line 114 def self.from_pson(data) new(data.delete('path'), data) end |
Instance Method Details
#attributes_with_tabs ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/file_serving/metadata.rb', line 24 def attributes_with_tabs raise(ArgumentError, "Cannot manage files of type #{ftype}") unless ['file','directory','link'].include? ftype desc = [] PARAM_ORDER.each { |check| check = :ftype if check == :type desc << send(check) } desc << checksum desc << @destination rescue nil if ftype == 'link' desc.join("\t") end |
#collect ⇒ Object
Retrieve the attributes for this file, relative to a base directory. Note that File.stat raises Errno::ENOENT if the file is absent and this method does not catch that exception.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/file_serving/metadata.rb', line 47 def collect real_path = full_path stat = stat() @owner = stat.uid @group = stat.gid @ftype = stat.ftype # We have to mask the mode, yay. @mode = stat.mode & 007777 case stat.ftype when "file" @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s when "directory" # Always just timestamp the directory. @checksum_type = "ctime" @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", path).to_s when "link" @destination = File.readlink(real_path) @checksum = ("{#{@checksum_type}}") + send("#{@checksum_type}_file", real_path).to_s rescue nil else raise ArgumentError, "Cannot manage files of type #{stat.ftype}" end end |
#to_pson(*args) ⇒ Object
110 111 112 |
# File 'lib/puppet/file_serving/metadata.rb', line 110 def to_pson(*args) to_pson_data_hash.to_pson(*args) end |
#to_pson_data_hash ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppet/file_serving/metadata.rb', line 87 def to_pson_data_hash { 'document_type' => 'FileMetadata', 'data' => super['data'].update( { 'owner' => owner, 'group' => group, 'mode' => mode, 'checksum' => { 'type' => checksum_type, 'value' => checksum }, 'type' => ftype, 'destination' => destination, }), 'metadata' => { 'api_version' => 1 } } end |