<commit_before>class RestFullApi::Api < ActionController::Base

  def index
    read_params
    @answer = []
    if @search_query.present?
      search(@model, @search_query, @requested_where, @requested_sort, @requested_offset, @requested_limit)
    else
      @total_count = (@model.where(@requested_where).count rescue @model.where(@requested_mongo_where))
      @records = (@model.where(@requested_where).order(@requested_sort).offset(@requested_offset).limit(@requested_limit).to_a rescue @model.where(@requested_mongo_where).order(@requeset_sort).offset(@requested_offset).limit(@requested_limit).to_a )
    end
    @records.each do |record|
      @answer.push get_record(record, @requested_fields, @requested_embed)
    end
    render_answer(@answer, 200)
  end

  def show
    record = @model.find_by_id(params[:record_id])
    create_error(:record_not_found) unless record.present?
    @answer = get_record(record, @requested_fields, @requested_embed)
    @total_count = 1
    response.headers[RestFullApi.configuration.version_option[@major][@minor][:headers][:created_at]] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:create_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z")
    response.headers["Last-Modified"] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:update_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z") 
    render_answer(@answer, 200)
  end

  def update
    record = @model.find_by_id(params[:record_id])
    @total_count = 1
    if record.present?
      response.headers[RestFullApi.configuration.version_option[@major][@minor][:headers][:created_at]] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:create_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z")
      response.headers["Last-Modified"] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:update_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z") 
      if (record.update_attributes(JSON.parse(request.body.read)) rescue false)
	render_answer(get_record(record, @requested_fields, @requested_embed), 200)
      else
	create_error(:not_updated)
      end
    else
      create_error(:record_not_found)
    end
  end

  def create
    record = @model.create(JSON.parse(request.body.read)) rescue create_error(:not_created)
    @total_count = 1
    if record.present?
      render_answer(get_record(record, @requested_fields, @requested_embed),201)
    else
      create_error(:not_created)
    end
  end

  def destroy
    record = @model.find_by_id(params[:record_id])
    if record.present?
      if record.destroy
	@answer = {status: 'destroyed'}
	render_answer(@answer, 204)
      else
	create_error(:not_destroyed)
      end
    else
      create_error(:record_not_found)
    end
  end

  def description
    @answer = RestFullApi.configuration.version_option[@major][@minor][:options][:model_description][@model.model_name.to_s.to_sym]
    render_answer(@answer, 200)
  end

  def edge
    if RestFullApi.configuration.version_option[@major][@minor][:options][:embed_accessible][@model.model_name.to_s.to_sym].include?(params[:edge].to_sym)
      @model = @model.where('rubrics.id = ?', params[:record_id]).first.send(params[:edge]) rescue create_error(:not_exist_edge)
      @api_attr_accessible = RestFullApi.configuration.version_option[@major][@minor][:options][:attributes_accessible][(@model.model_name.to_s.to_sym rescue @model.first.model_name.to_s.to_sym)]
      @api_embed_accessible = RestFullApi.configuration.version_option[@major][@minor][:options][:embed_accessible][(@model.model_name.to_s.to_sym rescue @model.first.model_name.to_s.to_sym)]
      read_params
      read_fields
      read_embeds
      @answer = []
      if @search_query.present?
	search(@model, @search_query, @requested_where, @requested_sort, @requested_offset, @requested_limit)
      else
	@total_count = (@model.where(@requested_where).count.length rescue @model.where(@requested_mongo_where).count)
	@records = (@model.where(@requested_where).order(@requested_sort).offset(@requested_offset).limit(@requested_limit).to_a rescue @model.where(@requested_mongo_where).order(@requeset_sort).offset(@requested_offset).limit(@requested_limit).to_a )
      end
      @records.each do |record|
	@answer.push get_record(record, @requested_fields, @requested_embed)
      end
      render_answer(@answer, 200) 
    else
      create_error(:not_exist_edge)
    end
  end


 before_filter :before 

  def search(model, query, where, sort, offset, limit)
    #TODO: This function write for "thinking sphinx, if your use another search engine override it
    @records = @model.search(query, where: where, order: sort, offset: offset, limit: limit)
    @total_count = @records.total_entries
  end

  def authorize?(login,pass)<commit_msg>Fix edge<commit_after>class RestFullApi::Api < ActionController::Base

  def index
    read_params
    @answer = []
    if @search_query.present?
      search(@model, @search_query, @requested_where, @requested_sort, @requested_offset, @requested_limit)
    else
      @total_count = (@model.where(@requested_where).count rescue @model.where(@requested_mongo_where))
      @records = (@model.where(@requested_where).order(@requested_sort).offset(@requested_offset).limit(@requested_limit).to_a rescue @model.where(@requested_mongo_where).order(@requeset_sort).offset(@requested_offset).limit(@requested_limit).to_a )
    end
    @records.each do |record|
      @answer.push get_record(record, @requested_fields, @requested_embed)
    end
    render_answer(@answer, 200)
  end

  def show
    record = @model.find_by_id(params[:record_id])
    create_error(:record_not_found) unless record.present?
    @answer = get_record(record, @requested_fields, @requested_embed)
    @total_count = 1
    response.headers[RestFullApi.configuration.version_option[@major][@minor][:headers][:created_at]] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:create_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z")
    response.headers["Last-Modified"] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:update_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z") 
    render_answer(@answer, 200)
  end

  def update
    record = @model.find_by_id(params[:record_id])
    @total_count = 1
    if record.present?
      response.headers[RestFullApi.configuration.version_option[@major][@minor][:headers][:created_at]] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:create_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z")
      response.headers["Last-Modified"] = record.send(RestFullApi.configuration.version_option[@major][@minor][:options][:update_timestamp]).strftime("%a, %d %b %Y %H:%M:%S %Z") 
      if (record.update_attributes(JSON.parse(request.body.read)) rescue false)
	render_answer(get_record(record, @requested_fields, @requested_embed), 200)
      else
	create_error(:not_updated)
      end
    else
      create_error(:record_not_found)
    end
  end

  def create
    record = @model.create(JSON.parse(request.body.read)) rescue create_error(:not_created)
    @total_count = 1
    if record.present?
      render_answer(get_record(record, @requested_fields, @requested_embed),201)
    else
      create_error(:not_created)
    end
  end

  def destroy
    record = @model.find_by_id(params[:record_id])
    if record.present?
      if record.destroy
	@answer = {status: 'destroyed'}
	render_answer(@answer, 204)
      else
	create_error(:not_destroyed)
      end
    else
      create_error(:record_not_found)
    end
  end

  def description
    @answer = RestFullApi.configuration.version_option[@major][@minor][:options][:model_description][@model.model_name.to_s.to_sym]
    render_answer(@answer, 200)
  end

  def edge
    if RestFullApi.configuration.version_option[@major][@minor][:options][:embed_accessible][@model.model_name.to_s.to_sym].include?(params[:edge].to_sym)
      @model = @model.where('rubrics.id = ?', params[:record_id]).first.send(params[:edge]) rescue create_error(:not_exist_edge)
      @api_attr_accessible = RestFullApi.configuration.version_option[@major][@minor][:options][:attributes_accessible][params[:edge].singularize.classify.to_sym]
      @api_embed_accessible = RestFullApi.configuration.version_option[@major][@minor][:options][:embed_accessible][params[:edge].singularize.classify.to_sym]
      read_params
      read_fields
      read_embeds
      @answer = []
      if @search_query.present?
	search(@model, @search_query, @requested_where, @requested_sort, @requested_offset, @requested_limit)
      else
	@total_count = (@model.where(@requested_where).count.length rescue @model.where(@requested_mongo_where).count)
	@records = (@model.where(@requested_where).order(@requested_sort).offset(@requested_offset).limit(@requested_limit).to_a rescue @model.where(@requested_mongo_where).order(@requeset_sort).offset(@requested_offset).limit(@requested_limit).to_a )
      end
      @records.each do |record|
	@answer.push get_record(record, @requested_fields, @requested_embed)
      end
      render_answer(@answer, 200) 
    else
      create_error(:not_exist_edge)
    end
  end


 before_filter :before 

  def search(model, query, where, sort, offset, limit)
    #TODO: This function write for "thinking sphinx, if your use another search engine override it
    @records = @model.search(query, where: where, order: sort, offset: offset, limit: limit)
    @total_count = @records.total_entries
  end

  def authorize?(login,pass)
{'fraction_non_alphanumeric': 0.1383189251119675, 'fraction_numerical': 0.004999479220914488, 'mean_word_length': 5.284031413612565, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2061199', 'n_tokens_mistral': 3192, 'n_tokens_neox': 3048, 'n_words': 474}