<commit_before>require 'representable'
module Radriar
  module Roar
    module KeyTranslation
      extend ActiveSupport::Concern

      class KeyTranslatorHash < Hashie::Mash
        protected
        def convert_key(key)
        end

        def convert_value(val, duping=false) #:nodoc
          obj = super
          obj = self.class.new(obj) if Hashie::Mash === obj
          obj if Hashie::Mash === obj
          obj
        end

        def initialize_reader(key)
          ck = to_underscore(key)
          custom_writer(ck, self.class.new) unless key?(ck)
          custom_reader(ck.camelize)
        end
      end

      class UnderscoreKeys < KeyTranslatorHash
        protected
        def convert_key(key)
          key.to_s.underscore
        end
      end

      class CamelizeKeys < KeyTranslatorHash
        protected
        def convert_key(key)
          key.to_s.camelize(:lower)
        end
      end


      module Representer
        def from_hash(data, options={}, binding_builder=::Representable::Hash::PropertyBinding)
          data = filter_wrap(UnderscoreKeys.new(data), options)
          update_properties_from(data, options, binding_builder)
        end

        def to_hash(options={}, binding_builder=::Representable::Hash::PropertyBinding)
          CamelizeKeys.new(super)
        end
      end

      included do
        ::Representable::Hash.prepend(Representer)

        Grape::Endpoint.class_eval do
          define_method(:params) do
            @params ||= UnderscoreKeys.new(@request.params)
          end
        end
      end
    end
  end
end<commit_msg>Fix constant lookup<commit_after>require 'representable'
module Radriar
  module Roar
    module KeyTranslation
      extend ActiveSupport::Concern

      class KeyTranslatorHash < Hashie::Mash
        protected
        def convert_key(key)
        end

        def convert_value(val, duping=false) #:nodoc
          obj = super
          obj = self.class.new(obj) if Hashie::Mash === obj
          obj if Hashie::Mash === obj
          obj
        end

        def initialize_reader(key)
          ck = to_underscore(key)
          custom_writer(ck, self.class.new) unless key?(ck)
          custom_reader(ck.camelize)
        end
      end

      class UnderscoreKeys < KeyTranslatorHash
        protected
        def convert_key(key)
          key.to_s.underscore
        end
      end

      class CamelizeKeys < KeyTranslatorHash
        protected
        def convert_key(key)
          key.to_s.camelize(:lower)
        end
      end


      module Representer
        def from_hash(data, options={}, binding_builder=::Representable::Hash::PropertyBinding)
          data = filter_wrap(UnderscoreKeys.new(data), options)
          update_properties_from(data, options, binding_builder)
        end

        def to_hash(options={}, binding_builder=::Representable::Hash::PropertyBinding)
          CamelizeKeys.new(super)
        end
      end

      included do
        ::Representable::Hash.prepend(Representer)

        ::Grape::Endpoint.class_eval do
          define_method(:params) do
            @params ||= UnderscoreKeys.new(@request.params)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07912772585669782, 'fraction_numerical': 0.0, 'mean_word_length': 2.0727272727272728, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '230030', 'n_tokens_mistral': 940, 'n_tokens_neox': 901, 'n_words': 195}