<commit_before>require 'objspace'

module Cenit
  class Utility

    class Proxy

      def initialize(obj, attributes = {})
        @obj = obj
        @attributes = attributes
      end

      def method(sym)
        @obj.method(sym)
      end

      def method_missing(symbol, *args)
        if @attributes.has_key?(symbol)
          @attributes[symbol]
        elsif @obj.respond_to?(symbol)
          @obj.send(symbol)
        else
          super
        end
      end

      def respond_to?(*args)
        @attributes.has_key?(args[0]) || @obj.respond_to?(*args) || super
      end
    end

    class << self
      def save(record, options = {})
        saved = options[:saved_collector] || Set.new
        if bind_references(record)
          if save_references(record, options, saved) && record.save
            true
          else
            for_each_node_starting_at(record, stack=[]) do |obj|
              obj.errors.each do |attribute, error|
                attr_ref = "#{obj.orm_model.data_type.title}" +
                  ((name = obj.try(:name)) || (name = obj.try(:title)) ? " #{name} on attribute " : "'s '") +
                  attribute.to_s #TODO Truck and do html safe for long values, i.e, XML Schemas ---> + ((v = obj.try(attribute)) ? "'#{v}'" : '')
                path = ''
                stack.reverse_each do |node|
                  node[:record].errors.add(node[:attribute], "with error on #{path}#{attr_ref} (#{error})") if node[:referenced]
                  path = node[:record].orm_model.data_type.title + ' -> '<commit_msg>Injecting options for cenit save utility<commit_after>require 'objspace'

module Cenit
  class Utility

    class Proxy

      def initialize(obj, attributes = {})
        @obj = obj
        @attributes = attributes
      end

      def method(sym)
        @obj.method(sym)
      end

      def method_missing(symbol, *args)
        if @attributes.has_key?(symbol)
          @attributes[symbol]
        elsif @obj.respond_to?(symbol)
          @obj.send(symbol)
        else
          super
        end
      end

      def respond_to?(*args)
        @attributes.has_key?(args[0]) || @obj.respond_to?(*args) || super
      end
    end

    class << self
      def save(record, options = {})
        saved = options[:saved_collector] || Set.new
        if bind_references(record)
          if save_references(record, options, saved) && record.save(options)
            true
          else
            for_each_node_starting_at(record, stack=[]) do |obj|
              obj.errors.each do |attribute, error|
                attr_ref = "#{obj.orm_model.data_type.title}" +
                  ((name = obj.try(:name)) || (name = obj.try(:title)) ? " #{name} on attribute " : "'s '") +
                  attribute.to_s #TODO Truck and do html safe for long values, i.e, XML Schemas ---> + ((v = obj.try(attribute)) ? "'#{v}'" : '')
                path = ''
                stack.reverse_each do |node|
                  node[:record].errors.add(node[:attribute], "with error on #{path}#{attr_ref} (#{error})") if node[:referenced]
                  path = node[:record].orm_model.data_type.title + ' -> '
{'fraction_non_alphanumeric': 0.1360759493670886, 'fraction_numerical': 0.0006329113924050633, 'mean_word_length': 1.9597378277153559, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5590111', 'n_tokens_mistral': 949, 'n_tokens_neox': 933, 'n_words': 215}