Class: Puppet::Util::FileParsing::FileRecord Private
- Includes:
- Puppet::Util
- Defined in:
- lib/puppet/util/fileparsing.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- INVALID_FIELDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[:record_type, :target, :on_disk]
Constants included from Puppet::Util
ALNUM, ALPHA, AbsolutePathPosix, AbsolutePathWindows, DEFAULT_POSIX_MODE, DEFAULT_WINDOWS_MODE, ESCAPED, HEX, HttpProxy, PUPPET_STACK_INSERTION_FRAME, RESERVED, RFC_3986_URI_REGEX, UNRESERVED, UNSAFE
Constants included from POSIX
POSIX::LOCALE_ENV_VARS, POSIX::USER_ENV_VARS
Constants included from SymbolicFileMode
SymbolicFileMode::SetGIDBit, SymbolicFileMode::SetUIDBit, SymbolicFileMode::StickyBit, SymbolicFileMode::SymbolicMode, SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary collapse
- #absent ⇒ Object private
- #block_eval ⇒ Object private
- #fields ⇒ Object private
- #joiner ⇒ Object private
- #match ⇒ Object private
- #name ⇒ Object private
- #optional ⇒ Object private
- #rollup ⇒ Object private
- #rts ⇒ Object private
- #separator ⇒ Object private
- #type ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(type, absent: nil, block_eval: nil, fields: nil, joiner: nil, match: nil, optional: nil, post_parse: nil, pre_gen: nil, rollup: nil, rts: nil, separator: nil, to_line: nil, &block) ⇒ FileRecord
constructor
private
A new instance of FileRecord.
-
#join(details) ⇒ Object
private
Convert a record into a line by joining the fields together appropriately.
-
#post_parse=(block) ⇒ Object
private
Create a hook that modifies the hash resulting from parsing.
-
#pre_gen=(block) ⇒ Object
private
Create a hook that modifies the hash just prior to generation.
-
#text? ⇒ Boolean
private
Are we a text type?.
- #to_line=(block) ⇒ Object private
Methods included from Puppet::Util
absolute_path?, benchmark, chuser, clear_environment, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
#initialize(type, absent: nil, block_eval: nil, fields: nil, joiner: nil, match: nil, optional: nil, post_parse: nil, pre_gen: nil, rollup: nil, rts: nil, separator: nil, to_line: nil, &block) ⇒ FileRecord
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.
Returns a new instance of FileRecord.
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 90 91 92 93 94 95 96 97 98 |
# File 'lib/puppet/util/fileparsing.rb', line 48 def initialize(type, absent: nil, block_eval: nil, fields: nil, joiner: nil, match: nil, optional: nil, post_parse: nil, pre_gen: nil, rollup: nil, rts: nil, separator: nil, to_line: nil, &block) @type = type.intern raise ArgumentError, _("Invalid record type %{record_type}") % { record_type: @type } unless [:record, :text].include?(@type) @absent = absent @block_eval = block_eval @joiner = joiner @match = match @rollup = rollup if rollup @rts = rts @separator = separator self.fields = fields if fields self.optional = optional if optional self.post_parse = post_parse if post_parse self.pre_gen = pre_gen if pre_gen self.to_line = to_line if to_line if self.type == :record # Now set defaults. self.absent ||= "" self.separator ||= /\s+/ self.joiner ||= " " self.optional ||= [] @rollup = true unless defined?(@rollup) end if block_given? @block_eval ||= :process # Allow the developer to specify that a block should be instance-eval'ed. if @block_eval == :instance instance_eval(&block) else (@block_eval, &block) end end end |
Instance Attribute Details
#absent ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def absent @absent end |
#block_eval ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def block_eval @block_eval end |
#fields ⇒ 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.
35 36 37 |
# File 'lib/puppet/util/fileparsing.rb', line 35 def fields @fields end |
#joiner ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def joiner @joiner end |
#match ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def match @match end |
#name ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def name @name end |
#optional ⇒ 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.
35 36 37 |
# File 'lib/puppet/util/fileparsing.rb', line 35 def optional @optional end |
#rollup ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def rollup @rollup end |
#rts ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def rts @rts end |
#separator ⇒ 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.
33 34 35 |
# File 'lib/puppet/util/fileparsing.rb', line 33 def separator @separator end |
#type ⇒ Object (readonly)
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.
35 36 37 |
# File 'lib/puppet/util/fileparsing.rb', line 35 def type @type end |
Instance Method Details
#join(details) ⇒ 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.
Convert a record into a line by joining the fields together appropriately. This is pulled into a separate method so it can be called by the hooks.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/puppet/util/fileparsing.rb', line 102 def join(details) joinchar = self.joiner fields.collect { |field| # If the field is marked absent, use the appropriate replacement if details[field] == :absent or details[field] == [:absent] or details[field].nil? if self.optional.include?(field) self.absent else raise ArgumentError, _("Field '%{field}' is required") % { field: field } end else details[field].to_s end }.reject { |c| c.nil?}.join(joinchar) end |
#post_parse=(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.
Create a hook that modifies the hash resulting from parsing.
127 128 129 |
# File 'lib/puppet/util/fileparsing.rb', line 127 def post_parse=(block) (:post_parse, &block) end |
#pre_gen=(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.
Create a hook that modifies the hash just prior to generation.
132 133 134 |
# File 'lib/puppet/util/fileparsing.rb', line 132 def pre_gen=(block) (:pre_gen, &block) end |
#text? ⇒ Boolean
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.
Are we a text type?
137 138 139 |
# File 'lib/puppet/util/fileparsing.rb', line 137 def text? type == :text end |
#to_line=(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.
141 142 143 |
# File 'lib/puppet/util/fileparsing.rb', line 141 def to_line=(block) (:to_line, &block) end |