<commit_before>module Dragonfly
  class ExtendedTempObject < TempObject
    
    # Exceptions
    class NotConfiguredError < RuntimeError; end
    
    class << self
      attr_accessor :app
    end
    
    def process(processing_method, *args)
      self.class.new(processor.send(processing_method, self, *args))
    end
    
    def process!(processing_method, *args)
      modify_self!(processor.send(processing_method, self, *args))
    end

    def encode(*args)
      self.class.new(encoder.encode(self, *args))
    end
    
    def encode!(*args)
      modify_self!(encoder.encode(self, *args))
    end
    
    def transform(*args)
      args.any? ? dup.transform!(*args) : self
    end
    
    def transform!(*args)
      parameters = parameters_class.from_args(*args)
      process!(parameters.processing_method, parameters.processing_options) unless parameters.processing_method.nil?
      encode!(parameters.format, parameters.encoding) unless parameters.format.nil?
      self
    end
    
    def public_methods
      super + analyser.analysis_methods
    end
    
    def respond_to?(method)
      super || analyser.has_analysis_method?(method)
    end

    private
    
    def method_missing(method, *args, &block)
      if analyser.has_analysis_method?(method)
        # Define the method so we don't use method_missing next time
        instance_var = "@#{method}"
        self.class.class_eval do
          define_method method do
            # Lazy reader, like
            #   @width ||= analyser.width(self)
            instance_variable_set(instance_var, instance_variable_get(instance_var) || analyser.send(method, self))
          end
        end
        # Now that it's defined (for next time)
        send(method)
      else
        super
      end
    end
    
    def app
      self.class.app ? self.class.app : raise(NotConfiguredError, "#{self.class} has no app set")
    end
    
    def analyser
      app.analyser
    end
    
    def processor
      app.processor
    end
    
    def encoder
      app.encoder
    end
    
    def parameters_class
      app.parameters_class
    end

  end
end<commit_msg>Modified public_methods and methods for extended temp object, so that e.g. autocomplete in console works<commit_after>module Dragonfly
  class ExtendedTempObject < TempObject
    
    # Exceptions
    class NotConfiguredError < RuntimeError; end
    
    class << self
      attr_accessor :app
    end
    
    def process(processing_method, *args)
      self.class.new(processor.send(processing_method, self, *args))
    end
    
    def process!(processing_method, *args)
      modify_self!(processor.send(processing_method, self, *args))
    end

    def encode(*args)
      self.class.new(encoder.encode(self, *args))
    end
    
    def encode!(*args)
      modify_self!(encoder.encode(self, *args))
    end
    
    def transform(*args)
      args.any? ? dup.transform!(*args) : self
    end
    
    def transform!(*args)
      parameters = parameters_class.from_args(*args)
      process!(parameters.processing_method, parameters.processing_options) unless parameters.processing_method.nil?
      encode!(parameters.format, parameters.encoding) unless parameters.format.nil?
      self
    end
    
    # Modify methods, public_methods and respond_to?, because method_missing
    # allows methods from the analyser
    
    def methods(*args)
      super + analyser.analysis_methods
    end
    
    def public_methods(*args)
      super + analyser.analysis_methods
    end
    
    def respond_to?(method)
      super || analyser.has_analysis_method?(method)
    end

    private
    
    def method_missing(method, *args, &block)
      if analyser.has_analysis_method?(method)
        # Define the method so we don't use method_missing next time
        instance_var = "@#{method}"
        self.class.class_eval do
          define_method method do
            # Lazy reader, like
            #   @width ||= analyser.width(self)
            instance_variable_set(instance_var, instance_variable_get(instance_var) || analyser.send(method, self))
          end
        end
        # Now that it's defined (for next time)
        send(method)
      else
        super
      end
    end
    
    def app
      self.class.app ? self.class.app : raise(NotConfiguredError, "#{self.class} has no app set")
    end
    
    def analyser
      app.analyser
    end
    
    def processor
      app.processor
    end
    
    def encoder
      app.encoder
    end
    
    def parameters_class
      app.parameters_class
    end

  end
end
{'fraction_non_alphanumeric': 0.08160593497708925, 'fraction_numerical': 0.0, 'mean_word_length': 2.3705882352941177, 'pattern_counts': {'":': 0, '<': 11, '<?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': '958865', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1320, 'n_words': 320}