# class FileServing::Configuration::Parser

### Constants

MODULES
Mount

### Public Instance Methods

parse() click to toggle source

Parse our configuration file.

    # File lib/puppet/file_serving/configuration/parser.rb, line 9
    def parse
      raise("File server configuration #{self.file} does not exist") unless FileTest.exists?(self.file)
      raise("Cannot read file server configuration #{self.file}") unless FileTest.readable?(self.file)

      @mounts = {}
      @count = 0

      File.open(self.file) { |f|
        mount = nil
        f.each_line { |line|
          # Have the count increment at the top, in case we throw exceptions.
          @count += 1

          case line
          when /^\s*#/; next # skip comments
          when /^\s*$/; next # skip blank lines
          when /\[([-\w]+)\]/
            mount = newmount($1)
          when /^\s*(\w+)\s+(.+?)(\s*#.*)?$/
            var = $1
            value = $2
            value.strip!
            raise(ArgumentError, "Fileserver configuration file does not use '=' as a separator") if value =~ /^=/
            case var
            when "path"
              path(mount, value)
            when "allow"
              allow(mount, value)
            when "deny"
              deny(mount, value)
            else
              raise ArgumentError.new("Invalid argument '#{var}'", @count, file)
            end
          else
            raise ArgumentError.new("Invalid line '#{line.chomp}'", @count, file)
          end
        }
      }

      validate

      @mounts
    end