Class: Puppet::Provider::PortageFile
- Inherits:
-
ParsedFile
- Object
- ParsedFile
- Puppet::Provider::PortageFile
- Defined in:
- lib/puppet/provider/portagefile.rb
Class Method Summary collapse
- .build_line(hash, sym = nil) ⇒ Object
-
.process_line(line, attribute = nil) ⇒ Hash
Define the :process FileRecord hook.
-
.to_line(hash) ⇒ String
Define the ParsedFile format hook.
Instance Method Summary collapse
Class Method Details
.build_line(hash, sym = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/provider/portagefile.rb', line 20 def self.build_line(hash, sym = nil) unless hash[:name] and hash[:name] != :absent raise ArgumentError, "name is a required attribute of portagefile providers" end str = Puppet::Util::Portage.format_atom(hash) if !sym.nil? and hash.include? sym if hash[sym].is_a? Array str << " " << hash[sym].join(" ") else str << " " << hash[sym] end end str end |
.process_line(line, attribute = nil) ⇒ Hash
Define the :process FileRecord hook
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/puppet/provider/portagefile.rb', line 43 def self.process_line(line, attribute = nil) hash = {} if !attribute.nil? and (match = line.match /^(\S+)\s+(.*)\s*$/) # if we have a package and an array of attributes. components = Puppet::Util::Portage.parse_atom(match[1]) # Try to parse version string if components[:compare] and components[:version] v = components[:compare] + components[:version] end hash[:name] = components[:package] hash[:version] = v if components[:slot] hash[:slot] = components[:slot].dup end attr_array = match[2].split(/\s+/) unless attr_array.empty? hash[attribute] = attr_array end elsif (match = line.match /^(\S+)\s*/) # just a package components = Puppet::Util::Portage.parse_atom(match[1]) # Try to parse version string if components[:compare] and components[:version] v = components[:compare] + components[:version] end hash[:name] = components[:package] hash[:version] = v if components[:slot] hash[:slot] = components[:slot].dup end else raise Puppet::Error, "Could not match '#{line}'" end hash end |
.to_line(hash) ⇒ String
Define the ParsedFile format hook
96 97 98 99 |
# File 'lib/puppet/provider/portagefile.rb', line 96 def self.to_line(hash) return super unless hash[:record_type] == :parsed build_line(hash) end |
Instance Method Details
#flush ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/puppet/provider/portagefile.rb', line 11 def flush # Ensure the target directory exists before creating file unless File.exist?(dir = File.dirname(target)) Dir.mkdir(dir) end super File.chmod(0644, target) end |