<commit_before>
require 'plist4r/config'
require 'plist4r/mixin/ordered_hash'

module Plist4r
  module DataMethods

    # Return those Class constants which the value of a Plist Key must conform to.
    # This is class-based data validation.
    ClassesForKeyType = 
    {
      :string => [String], 
      :bool => [TrueClass,FalseClass],
      :bool_or_string => [TrueClass,FalseClass,String],
      :integer => [Fixnum], 
      :array_of_strings => [Array],
      :array_of_hashes => [Array],
      :array => [Array],
      :array_or_integer => [Array,Fixnum],
      :array_or_hash => [Array, Hash],
      :hash_of_bools => [Hash],
      :hash_of_strings => [Hash],
      :hash_of_arrays => [Hash],
      :hash_of_arrays_of_strings => [Hash],
      :hash => [Hash],
      :bool_or_hash_of_bools => [TrueClass,FalseClass,Hash],
      :bool_or_string_or_array_of_strings => [TrueClass,FalseClass,String,Array]
    }

    # A Hash Array of the supported plist keys for this type. These are only those plist keys 
    # recognized as belonging to a specific plist datatype. Used in validation, part of DataMethods.
    # We usually overload this method in subclasses. To see how to use these Plist Keys, go to {file:PlistKeyNames}
    # @example
    #  class Plist4r::PlistType::MyPlistType < PlistType
    #    ValidKeys =
    #    {
    #       :string => %w[PlistKeyS1 PlistKeyS2 ...],
    #       :bool => %w[PlistKeyB1 PlistKeyB2 ...],
    #       :integer => %w[PlistKeyI1 PlistKeyI2 ...],
    #       :method_defined => %w[CustomPlistKey1 CustomPlistKey2 ...]
    #    }
    #  end
    #
    #  plist.plist_type :my_plist_type
    #  plist.plist_key_s1 "some string"
    #  plist.plist_key_b1 true
    #  plist.plist_key_i1 08
    #  plist.custom_plist_key1 MyClass.new(opts)
    # @see ClassesForKeyType
    ValidKeys = {}

    # A template for creating new plist types
    ValidKeysTemplate =
    {
      :string => %w[
        
        ],
      :bool => %w[
        
        ],
      :integer => %w[
        
        ],
      :array_of_strings => %w[
        
        ],
      :array_of_hashes => %w[
        
        ],
      :array => %w[
        
        ],
      :hash_of_bools => %w[
        
        ],
      :hash_of_strings => %w[
        
        ],
      :hash_of_arrays => %w[
        
        ],
      :hash_of_arrays_of_strings => %w[
        
        ],
      :hash => %w[
        
        ],
      :could_be_method_defined   => %w[
        
        ]
    }

    # Defining respond_to? conflicts with rspec 1.3.0. @object.stub() blows up.
    # To as a consequence we dont implement respond_to? for method_missing()
    # @return true
    def _respond_to? method_sym
      true
    end

    # Call {#set_or_return} with the appropriate arguments. If {Plist4r::Plist#strict_keys} is enabled, 
    # then raise an error on any unrecognised Plist Keys.
    def method_missing method_symbol, *args, &blk
      set_or_return method_symbol.to_s.camelcase, *args, &blk
    end

    # Set or return value data
    # @param [Symbol, String] key The plist key name, either a snake-cased symbol, or literal string
    # @param [nil, Object] value If present, store Object under the plist key "key". If nil, return the stored object
    # @return The Object stored under key
    def set_or_return key, value=nil
      key = key.to_s.camelcase if key.class == Symbol

      self.class::ValidKeys.each do |key_type, valid_keys_of_those_type|
        if valid_keys_of_those_type.include?(key)
          return set_or_return_of_type key_type, key, value
        end
      end

      unless @plist.strict_keys<commit_msg>Fix a bug where in some cases the strict keys setting was previously being ignored<commit_after>
require 'plist4r/config'
require 'plist4r/mixin/ordered_hash'

module Plist4r
  module DataMethods

    # Return those Class constants which the value of a Plist Key must conform to.
    # This is class-based data validation.
    ClassesForKeyType = 
    {
      :string => [String], 
      :bool => [TrueClass,FalseClass],
      :bool_or_string => [TrueClass,FalseClass,String],
      :integer => [Fixnum], 
      :array_of_strings => [Array],
      :array_of_hashes => [Array],
      :array => [Array],
      :array_or_integer => [Array,Fixnum],
      :array_or_hash => [Array, Hash],
      :hash_of_bools => [Hash],
      :hash_of_strings => [Hash],
      :hash_of_arrays => [Hash],
      :hash_of_arrays_of_strings => [Hash],
      :hash => [Hash],
      :bool_or_hash_of_bools => [TrueClass,FalseClass,Hash],
      :bool_or_string_or_array_of_strings => [TrueClass,FalseClass,String,Array]
    }

    # A Hash Array of the supported plist keys for this type. These are only those plist keys 
    # recognized as belonging to a specific plist datatype. Used in validation, part of DataMethods.
    # We usually overload this method in subclasses. To see how to use these Plist Keys, go to {file:PlistKeyNames}
    # @example
    #  class Plist4r::PlistType::MyPlistType < PlistType
    #    ValidKeys =
    #    {
    #       :string => %w[PlistKeyS1 PlistKeyS2 ...],
    #       :bool => %w[PlistKeyB1 PlistKeyB2 ...],
    #       :integer => %w[PlistKeyI1 PlistKeyI2 ...],
    #       :method_defined => %w[CustomPlistKey1 CustomPlistKey2 ...]
    #    }
    #  end
    #
    #  plist.plist_type :my_plist_type
    #  plist.plist_key_s1 "some string"
    #  plist.plist_key_b1 true
    #  plist.plist_key_i1 08
    #  plist.custom_plist_key1 MyClass.new(opts)
    # @see ClassesForKeyType
    ValidKeys = {}

    # A template for creating new plist types
    ValidKeysTemplate =
    {
      :string => %w[
        
        ],
      :bool => %w[
        
        ],
      :integer => %w[
        
        ],
      :array_of_strings => %w[
        
        ],
      :array_of_hashes => %w[
        
        ],
      :array => %w[
        
        ],
      :hash_of_bools => %w[
        
        ],
      :hash_of_strings => %w[
        
        ],
      :hash_of_arrays => %w[
        
        ],
      :hash_of_arrays_of_strings => %w[
        
        ],
      :hash => %w[
        
        ],
      :could_be_method_defined   => %w[
        
        ]
    }

    # Defining respond_to? conflicts with rspec 1.3.0. @object.stub() blows up.
    # To as a consequence we dont implement respond_to? for method_missing()
    # @return true
    def _respond_to? method_sym
      true
    end

    # Call {#set_or_return} with the appropriate arguments. If {Plist4r::Plist#strict_keys} is enabled, 
    # then raise an error on any unrecognised Plist Keys.
    def method_missing method_symbol, *args, &blk
      set_or_return method_symbol.to_s.camelcase, *args, &blk
    end

    # Set or return value data
    # @param [Symbol, String] key The plist key name, either a snake-cased symbol, or literal string
    # @param [nil, Object] value If present, store Object under the plist key "key". If nil, return the stored object
    # @return The Object stored under key
    def set_or_return key, value=nil
      key = key.to_s.camelcase if key.class == Symbol

      self.class::ValidKeys.each do |key_type, valid_keys_of_those_type|
        if valid_keys_of_those_type.include?(key)
          return set_or_return_of_type key_type, key, value
        end
      end

      if (! @plist) || (@plist && @plist.strict_keys == false)
{'fraction_non_alphanumeric': 0.10674462877345663, 'fraction_numerical': 0.005983138428066358, 'mean_word_length': 2.292300805729633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6592387', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2389, 'n_words': 614}