<commit_before>module RelaxDB
    
  class Document
    
    # Define properties and property methods
    
    def self.property(prop, opts={})
      # Class instance varibles are not inherited, so the default properties must be explicitly listed 
      # Perhaps a better solution exists. Revise. I think extlib contains a solution for this...
      @properties ||= [:_id, :_rev]
      @properties << prop

      define_method(prop) do
        instance_variable_get("@#{prop}".to_sym)        
      end

      define_method("#{prop}=") do |val|
        instance_variable_set("@#{prop}".to_sym, val)
      end
      
      if opts[:default]
        define_method("set_default_#{prop}") do
          default = opts[:default]
          default = default.is_a?(Proc) ? default.call : default
          instance_variable_set("@#{prop}".to_sym, default)
        end
      end
    end

    def self.properties
      # Ensure that classes that don't define their own properties still function as CouchDB objects
      @properties ||= [:_id, :_rev]
    end

    def properties
      self.class.properties
    end
    
    # Specifying these properties here is kinda ugly. Consider a better solution.
    property :_id 
    property :_rev    
    
    def initialize(hash={})
      # The default _id will be overwritten if loaded from CouchDB
      self._id = UuidGenerator.uuid 

      # Set default properties if this object has not known CouchDB
      unless hash["_rev"]
        properties.each do |prop|
         if self.class.instance_methods.include?("set_default_#{prop}")
           send("set_default_#{prop}")
         end
        end
      end
      
      set_attributes(hash)
    end
    
    def set_attributes(data)
      data.each do |key, val|
        # Only set instance variables on creation - object references are resolved on demand

        # If the variable name ends in _at try to convert it to a Time
        if key =~ /_at$/
            val = Time.local(*ParseDate.parsedate(val)) rescue val
        end

        # If an object has been passed to the constructor, invoke its assignment method
        if self.class.all_relationships.include? key
          send("#{key}=".to_sym, val)
        end
                  
        instance_variable_set("@#{key}".to_sym, val)
      end
    end  
    
    def inspect<commit_msg>Fix what looks like a minor bug<commit_after>module RelaxDB
    
  class Document
    
    # Define properties and property methods
    
    def self.property(prop, opts={})
      # Class instance varibles are not inherited, so the default properties must be explicitly listed 
      # Perhaps a better solution exists. Revise. I think extlib contains a solution for this...
      @properties ||= [:_id, :_rev]
      @properties << prop

      define_method(prop) do
        instance_variable_get("@#{prop}".to_sym)        
      end

      define_method("#{prop}=") do |val|
        instance_variable_set("@#{prop}".to_sym, val)
      end
      
      if opts[:default]
        define_method("set_default_#{prop}") do
          default = opts[:default]
          default = default.is_a?(Proc) ? default.call : default
          instance_variable_set("@#{prop}".to_sym, default)
        end
      end
    end

    def self.properties
      # Ensure that classes that don't define their own properties still function as CouchDB objects
      @properties ||= [:_id, :_rev]
    end

    def properties
      self.class.properties
    end
    
    # Specifying these properties here is kinda ugly. Consider a better solution.
    property :_id 
    property :_rev    
    
    def initialize(hash={})
      # The default _id will be overwritten if loaded from CouchDB
      self._id = UuidGenerator.uuid 

      # Set default properties if this object has not known CouchDB
      unless hash["_rev"]
        properties.each do |prop|
         if self.class.instance_methods.include?("set_default_#{prop}")
           send("set_default_#{prop}")
         end
        end
      end
      
      set_attributes(hash)
    end
    
    def set_attributes(data)
      data.each do |key, val|
        # Only set instance variables on creation - object references are resolved on demand

        # If the variable name ends in _at try to convert it to a Time
        if key =~ /_at$/
            val = Time.local(*ParseDate.parsedate(val)) rescue val
        end

        # If an object has been passed to the constructor, invoke its assignment method
        if self.class.all_relationships.include? key
          send("#{key}=".to_sym, val)
        else  
          instance_variable_set("@#{key}".to_sym, val)
        end
        
      end
    end  
    
    def inspect
{'fraction_non_alphanumeric': 0.08427324962758033, 'fraction_numerical': 0.0, 'mean_word_length': 2.1671159029649596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1169384', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1296, 'n_words': 428}