Sha256: 3b0e1362bd0c598e8ce5d763fff72ddcb0d577b6963d4c3397efb1074a191d9f

Contents?: true

Size: 879 Bytes

Versions: 11

Compression:

Stored size: 879 Bytes

Contents

module Controller::QueryConditions
  private

  def add_conditions_from_query(scope)
    query_params.each do |field, condition|
      case field
      when 'limit'
        scope = scope.limit(condition.to_i)
      when 'offset'
        scope = scope.offset(condition.to_i)
      when 'order'
        scope = scope.order(condition)
      when 'includes'
        scope = scope.includes(condition.map(&:to_sym))
      else
        condition_statement = ::Api::ResourcesController::ConditionParser.new(scope, field, condition).condition_statement
        scope = scope.where(condition_statement)
      end
    end
    scope
  end

  def query_params
    default_query_params
  end

  def default_query_params
    request.query_parameters.except(*default_query_params_exceptions)
  end

  def default_query_params_exceptions
    %w(sort_by sort_direction utf8 commit page)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails-add_ons-2.2.1 app/concerns/controller/query_conditions.rb
rails-add_ons-2.2.0 app/concerns/controller/query_conditions.rb
rails-add_ons-2.1.1 app/concerns/controller/query_conditions.rb
rails-add_ons-2.1.0 app/concerns/controller/query_conditions.rb
rails-add_ons-2.0.2 app/concerns/controller/query_conditions.rb
rails-add_ons-2.0.1 app/concerns/controller/query_conditions.rb
rails-add_ons-2.0.0 app/concerns/controller/query_conditions.rb
rails-add_ons-1.5.2 app/concerns/controller/query_conditions.rb
rails-add_ons-1.5.1 app/concerns/controller/query_conditions.rb
rails-add_ons-1.5.0 app/concerns/controller/query_conditions.rb
rails-add_ons-1.4.1 app/concerns/controller/query_conditions.rb