<commit_before>require 'active_support/inflector'

module  Targetprocess
  module Base
    
    def self.included(base)
      base.send(:include, InstanceMethods)
      base.extend(ClassMethods)
    end
    
    attr_reader :attributes, :changed_attributes

    module InstanceMethods
      def initialize(hash={})
        @changed_attributes = hash
        @attributes = {}
      end
      
      def delete
        path = entity_path
        resp = Targetprocess.client.delete(path)
        true if resp.code == "200"
      end

      def save 
        path = self.class.collection_path
        @changed_attributes.merge!(id: @attributes[:id]) if @attributes[:id]
        resp = Targetprocess.client.post(path, @changed_attributes)
        @changed_attributes = {}
        @attributes.merge!(resp)
        self
      end

      def ==(obj)
        if self.class == obj.class && self.all_attrs-obj.all_attrs==[]
          (self.all_attrs|obj.all_attrs).all? do 
            |key| self.send(key) == obj.send(key)
          end
        else 
          false
        end
      end

      def method_missing(name, *args)
        if self.respond_to?(name)
          if name.to_s.match(/=\z/) 
            key = name.to_s.delete("=").to_sym
            if @attributes[key] == args.first
              @changed_attributes.delete(key)
            else
              @changed_attributes[key] = args.first
            end
          else
            @changed_attributes[name] or @attributes[name] 
          end
        else 
          super
        end  
      end
      
      def respond_to_missing?(name, include_private = false)
        if name.to_s.match(/\A[a-z_]+\z/) && self.all_attrs.include?(name)
          true
        elsif name.to_s.match(/\A[a-z_]+=\z/) && name != :id=
          true
        else 
          super 
        end
      end
<commit_msg>method_missing hot fix<commit_after>require 'active_support/inflector'

module  Targetprocess
  module Base
    
    def self.included(base)
      base.send(:include, InstanceMethods)
      base.extend(ClassMethods)
    end
    
    attr_reader :attributes, :changed_attributes

    module InstanceMethods
      def initialize(hash={})
        @changed_attributes = hash
        @attributes = {}
      end
      
      def delete
        path = entity_path
        resp = Targetprocess.client.delete(path)
        true if resp.code == "200"
      end

      def save 
        path = self.class.collection_path
        @changed_attributes.merge!(id: @attributes[:id]) if @attributes[:id]
        resp = Targetprocess.client.post(path, @changed_attributes)
        @changed_attributes = {}
        @attributes.merge!(resp)
        self
      end

      def ==(obj)
        if self.class == obj.class && self.all_attrs-obj.all_attrs==[]
          (self.all_attrs|obj.all_attrs).all? do 
            |key| self.send(key) == obj.send(key)
          end
        else 
          false
        end
      end

      def method_missing(name, *args)
        if self.respond_to?(name)
          if name.to_s.match(/=\z/) 
            key = name.to_s.delete("=").to_sym
            if @attributes[key] == args.first
              @changed_attributes.delete(key)
            else
              @changed_attributes[key] = args.first
            end
          else
            if @changed_attributes.has_key?(name)
              @changed_attributes[name] 
            else
              @attributes[name] 
            end
          end
        else 
          super
        end  
      end
      
      def respond_to_missing?(name, include_private = false)
        if name.to_s.match(/\A[a-z_]+\z/) && self.all_attrs.include?(name)
          true
        elsif name.to_s.match(/\A[a-z_]+=\z/) && name != :id=
          true
        else 
          super 
        end
      end

{'fraction_non_alphanumeric': 0.10502881089575694, 'fraction_numerical': 0.001571503404924044, 'mean_word_length': 1.6557719054242004, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3796312', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1108, 'n_words': 221}