<commit_before>#   Copyright 2014 Brainsware
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

require 'puppetx/filemapper'

Puppet::Type.type(:trafficserver_storage).provide(:storage) do

  desc 'Apache TrafficServer provider for parsing and writing storage.config'

  include PuppetX::FileMapper

  commands :mkdir  => 'mkdir',
           :chown  => 'chown'

  @default_target = '/etc/trafficserver/storage.config'
  @blank      = /^\s*$/
  @comment    = /^\s*#/
  @line_match =  %r{
      ^[ \t]*  # optional starting space, this is important of the repetition matcher below
      (.+?)    # match the whole bloody line, and we'll take it apart later.
      [ \t]*$  # optional: trailing spaces
    }x


  def select_file
    @default_target
  end

  def self.target_files
    [ @default_target ]
  end

  def self.parse_file(filename, file_contents)
    lines = file_contents.split("\n")

    real_lines = lines.delete_if { |l| l =~ @blank || l =~ @comment }

    real_lines.collect { |line| line.match(@line_match) }.compact.collect do |m|

      line_match    = m[1]
      conf, comment = line_match.split('#', 2) # catch comments in comments ;)
      path, *size   = conf.split
      comment       = comment.strip unless comment.nil?

      # validate, that which cannot be sensibly validated in the type:
      raise Puppet::ParseError, "Invalid format: <path> [<size>]" if size.size > 1

      # init @property_hash, by returning a hash
      {
        :name     => path,
        :path     => path,
        :size     => size.first,
        :comment  => comment,
      }
    end
  end<commit_msg>use constants rather than instance variables<commit_after>#   Copyright 2014 Brainsware
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

require 'puppetx/filemapper'

Puppet::Type.type(:trafficserver_storage).provide(:storage) do

  desc 'Apache TrafficServer provider for parsing and writing storage.config'

  include PuppetX::FileMapper

  commands :mkdir  => 'mkdir',
           :chown  => 'chown'

  Default_target = '/etc/trafficserver/storage.config'
  Blank      = /^\s*$/
  Comment    = /^\s*#/
  Line_match =  %r{
      ^[ \t]*  # optional starting space, this is important of the repetition matcher below
      (.+?)    # match the whole bloody line, and we'll take it apart later.
      [ \t]*$  # optional: trailing spaces
    }x


  def select_file
    Default_target
  end

  def self.target_files
    [ Default_target ]
  end

  def self.parse_file(filename, file_contents)
    lines = file_contents.split("\n")

    real_lines = lines.delete_if { |l| l =~ Blank || l =~ Comment }

    real_lines.collect { |line| line.match(Line_match) }.compact.collect do |m|

      line_match    = m[1]
      conf, comment = line_match.split('#', 2) # catch comments in comments ;)
      path, *size   = conf.split
      comment       = comment.strip unless comment.nil?

      # validate, that which cannot be sensibly validated in the type:
      raise Puppet::ParseError, "Invalid format: <path> [<size>]" if size.size > 1

      # init @property_hash, by returning a hash
      {
        :name     => path,
        :path     => path,
        :size     => size.first,
        :comment  => comment,
      }
    end
  end
{'fraction_non_alphanumeric': 0.1039906103286385, 'fraction_numerical': 0.005164319248826291, 'mean_word_length': 2.804464285714286, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6075534', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1250, 'n_words': 438}