<commit_before>class Throne::Document < Hashie::Mash
  class NotFound < StandardError; end
  
  ## Class methods
  class << self   
    # Create a new document and persist it to the database
    # @params [Hash] Properties to be persisted
    def create(attributes = {})
      new.save(attributes)
    end
    
    # Get a document from the database
    # @param [String] docid the ID of the document to retrieve
    # @param [String] rev (optional) the revision of the document to retrieve
    # @return [Hash, nil] the document mapped to a hash, or nil if not found.
    def get(id, revision = nil)
      begin
        unless revision
          response = Throne::Request.get(:resource => id)
        else
          response = Throne::Request.get(:resource => id, :params => {:rev => _rev})
        end
        
        new.merge(response)
      rescue RestClient::ResourceNotFound
        raise NotFound
      end
    end
    
    # Remove a document from the database
    # @param [String] Document ID
    # @return [boolean]
    def destroy(id)
      get(id).destroy
    rescue Throne::Document::NotFound
      true
    end
  end
  
  ## Instance methods
  
  def _id; self[:_id]; end<commit_msg>Set the ruby_class name on init<commit_after>class Throne::Document < Hashie::Mash
  class NotFound < StandardError; end
  
  ## Class methods
  class << self   
    # Create a new document and persist it to the database
    # @params [Hash] Properties to be persisted
    def create(attributes = {})
      new.save(attributes)
    end
    
    # Get a document from the database
    # @param [String] docid the ID of the document to retrieve
    # @param [String] rev (optional) the revision of the document to retrieve
    # @return [Hash, nil] the document mapped to a hash, or nil if not found.
    def get(id, revision = nil)
      begin
        unless revision
          response = Throne::Request.get(:resource => id)
        else
          response = Throne::Request.get(:resource => id, :params => {:rev => _rev})
        end
        
        new.merge(response)
      rescue RestClient::ResourceNotFound
        raise NotFound
      end
    end
    
    # Remove a document from the database
    # @param [String] Document ID
    # @return [boolean]
    def destroy(id)
      get(id).destroy
    rescue Throne::Document::NotFound
      true
    end
  end
  
  ## Instance methods
  
  def initialize(attributes = nil, default = nil, &block)
    self[:ruby_class] = self.class.name
    super(attributes, default, &block)
  end
  
  def _id; self[:_id]; end
{'fraction_non_alphanumeric': 0.08963367108339829, 'fraction_numerical': 0.0, 'mean_word_length': 2.441018766756032, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2812288', 'n_tokens_mistral': 730, 'n_tokens_neox': 721, 'n_words': 262}