<commit_before>require 'active_support/core_ext/array'

require 'simple_enum/enum'
require 'simple_enum/hasher'
require 'simple_enum/accessors'

module SimpleEnum

  # SimpleEnum::Attribute is the base class to be included in objects to get
  # the #as_enum functionality. All the including class needs to provide is
  # a setter and getter for `source`, by default the `source` is `<enum>_cd`.
  # This is similar to how relations work in Rails, the idea is not taint the
  # original method.
  #
  module Attribute
    def as_enum(name, values, options = {})
      options.assert_valid_keys(:source, :prefix, :with, :accessor, :builder)

      hash     = SimpleEnum::Hasher.map(values, options)
      enum     = SimpleEnum::Enum.new(name, hash)
      accessor = SimpleEnum::Accessors.accessor(name, enum, options)

      generate_enum_class_accessors_for(enum, accessor)
      generate_enum_instance_accessors_for(enum, accessor)

      Array.wrap(options.fetch(:with, SimpleEnum.with)).each do |feature|
        send "generate_enum_#{feature}_methods_for", enum, accessor
      end

      enum
    end

    private

    def simple_enum_module
      @simple_enum_module ||= Module.new.tap { |mod| include mod }<commit_msg>assert valid keys, use map: instead of builder:<commit_after>require 'active_support/core_ext/array'

require 'simple_enum/enum'
require 'simple_enum/hasher'
require 'simple_enum/accessors'

module SimpleEnum

  # SimpleEnum::Attribute is the base class to be included in objects to get
  # the #as_enum functionality. All the including class needs to provide is
  # a setter and getter for `source`, by default the `source` is `<enum>_cd`.
  # This is similar to how relations work in Rails, the idea is not taint the
  # original method.
  #
  module Attribute
    def as_enum(name, values, options = {})
      options.assert_valid_keys(:source, :prefix, :with, :accessor, :map)

      hash     = SimpleEnum::Hasher.map(values, options)
      enum     = SimpleEnum::Enum.new(name, hash)
      accessor = SimpleEnum::Accessors.accessor(name, enum, options)

      generate_enum_class_accessors_for(enum, accessor)
      generate_enum_instance_accessors_for(enum, accessor)

      Array.wrap(options.fetch(:with, SimpleEnum.with)).each do |feature|
        send "generate_enum_#{feature}_methods_for", enum, accessor
      end

      enum
    end

    private

    def simple_enum_module
      @simple_enum_module ||= Module.new.tap { |mod| include mod }
{'fraction_non_alphanumeric': 0.09322033898305085, 'fraction_numerical': 0.0, 'mean_word_length': 3.841796875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6585222', 'n_tokens_mistral': 753, 'n_tokens_neox': 738, 'n_words': 219}