<commit_before>class RestfulModel

  attr_accessor :_id
  attr_accessor :created_at

  def self.collection_name
    "#{self.to_s.downcase}s"
  end


  def initialize(parent)
    if parent.is_a?(Populr)
      @_api = parent
    else
      @_parent = parent
      @_api = parent.instance_variable_get :@_api
    end
  end

  def ==(comparison_object)
    comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object._id == _id)
  end

  def inflate(json)
    setters = methods.grep(/^\w+=$/)
    setters.each do |setter|
      property_name = setter.to_s[0..setter.to_s.index('=')-1]
      self.send(setter, json[property_name]) if json.has_key?(property_name)
    end
    self.created_at = Time.parse(self.created_at) if self.created_at
  end

  def save!
    if _id
      update('PUT', '', self.as_json(:api_representation => true))
    else
      update('POST', '', self.as_json(:api_representation => true))
    end
  end

  def as_json(options = {})
    hash = {}
    setters = methods.grep(/^\w+=$/)
    setters.each do |setter|
      getter = setter.to_s[0..setter.to_s.index('=')-1]
      unless options[:except] && options[:except].include?(getter)
        value = self.send(getter)
        unless value.is_a? RestfulModelCollection
          hash[getter] = value
          if value.class.method_defined? :as_json
            value = value.as_json(options)
          end
        end
      end
    end
    hash
  end

  def update(http_method, action, data = {})
    http_method = http_method.downcase
    action_url = @_api.url_for_path(self.path(action))

    RestClient.send(http_method, action_url, data){ |response,request,result|
      json = Populr.interpret_response(result, response, {:expected_class => Object})
      inflate(json)
    }
    self
  end

  def path(action = "")
    action = "/#{action}" unless action.empty?
    prefix = @_parent ? @_parent.path : ''
    "#{prefix}#{_id}#{action}"
  end<commit_msg>Added destroy command to the pop model in the API<commit_after>class RestfulModel

  attr_accessor :_id
  attr_accessor :created_at

  def self.collection_name
    "#{self.to_s.downcase}s"
  end


  def initialize(parent)
    if parent.is_a?(Populr)
      @_api = parent
    else
      @_parent = parent
      @_api = parent.instance_variable_get :@_api
    end
  end

  def ==(comparison_object)
    comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object._id == _id)
  end

  def inflate(json)
    setters = methods.grep(/^\w+=$/)
    setters.each do |setter|
      property_name = setter.to_s[0..setter.to_s.index('=')-1]
      self.send(setter, json[property_name]) if json.has_key?(property_name)
    end
    self.created_at = Time.parse(self.created_at) if self.created_at
  end

  def save!
    if _id
      update('PUT', '', self.as_json(:api_representation => true))
    else
      update('POST', '', self.as_json(:api_representation => true))
    end
  end

  def as_json(options = {})
    hash = {}
    setters = methods.grep(/^\w+=$/)
    setters.each do |setter|
      getter = setter.to_s[0..setter.to_s.index('=')-1]
      unless options[:except] && options[:except].include?(getter)
        value = self.send(getter)
        unless value.is_a? RestfulModelCollection
          hash[getter] = value
          if value.class.method_defined? :as_json
            value = value.as_json(options)
          end
        end
      end
    end
    hash
  end

  def update(http_method, action, data = {})
    http_method = http_method.downcase
    action_url = @_api.url_for_path(self.path(action))
    RestClient.send(http_method, action_url, data){ |response,request,result|
      unless http_method == 'delete'
        json = Populr.interpret_response(result, response, {:expected_class => Object})
        inflate(json)
      end
    }
    self
  end

  def destroy
    update('DELETE', '')
  end

  def path(action = "")
    action = "/#{action}" unless action.empty?
    prefix = @_parent ? @_parent.path : ''
    "#{prefix}#{_id}#{action}"
  end
{'fraction_non_alphanumeric': 0.13285854616895873, 'fraction_numerical': 0.0019646365422396855, 'mean_word_length': 2.9088291746641075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6677692', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1392, 'n_words': 266}