# class Puppet::Util::FileParsing::FileRecord

### Constants

INVALID_FIELDS

### Attributes

absent[RW]
block_eval[RW]
fields[R]
joiner[RW]
match[RW]
name[RW]
optional[R]
rollup[RW]
rts[RW]
separator[RW]
type[R]

### Public Class Methods

new(type, options = {}, &block) click to toggle source

    # File lib/puppet/util/fileparsing.rb, line 51
    def initialize(type, options = {}, &block)
      @type = type.intern
      raise ArgumentError, "Invalid record type #{@type}" unless [:record, :text].include?(@type)

      set_options(options)

      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
          meta_def(@block_eval, &block)
        end
      end
    end

### Public Instance Methods

fields=(fields) click to toggle source

Customize this so we can do a bit of validation.

    # File lib/puppet/util/fileparsing.rb, line 43
    def fields=(fields)
      @fields = fields.collect do |field|
        r = field.intern
        raise ArgumentError.new("Cannot have fields named #{r}") if INVALID_FIELDS.include?(r)
        r
      end
    end

join(details) click to toggle source

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.

    # File lib/puppet/util/fileparsing.rb, line 80
    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"
          end
        else
          details[field].to_s
        end
      }.reject { |c| c.nil?}.join(joinchar)
    end

optional=(optional) click to toggle source

Customize this so we can do a bit of validation.

    # File lib/puppet/util/fileparsing.rb, line 98
    def optional=(optional)
      @optional = optional.collect do |field|
        field.intern
      end
    end

post_parse=(block) click to toggle source

Create a hook that modifies the hash resulting from parsing.

    # File lib/puppet/util/fileparsing.rb, line 105
    def post_parse=(block)
      meta_def(:post_parse, &block)
    end

pre_gen=(block) click to toggle source

Create a hook that modifies the hash just prior to generation.

    # File lib/puppet/util/fileparsing.rb, line 110
    def pre_gen=(block)
      meta_def(:pre_gen, &block)
    end

text?() click to toggle source

Are we a text type?

    # File lib/puppet/util/fileparsing.rb, line 115
    def text?
      type == :text
    end

to_line=(block) click to toggle source

    # File lib/puppet/util/fileparsing.rb, line 119
    def to_line=(block)
      meta_def(:to_line, &block)
    end