Module: Myprocessor

Defined in:
lib/myprocessor.rb,
lib/myprocessor/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#include_processorObject



27
28
29
30
31
32
# File 'lib/myprocessor.rb', line 27

def include_processor
  return false if params[:include].blank?
  params[:include].split(',').map(&:strip).each do | value|
  send(value)
  end
end

#param_processor(table_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/myprocessor.rb', line 5

def param_processor(table_name)
  request.query_parameters.each do |key, value|
    if value == "true"
      value = true
    elsif value == "false"
      value = false
    else
      value = value.split(',')
    end
    search_collection(table_name, key, value)
  end
end

#search_collection(collection, key, value) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/myprocessor.rb', line 18

def search_collection(collection, key, value)
  if ActiveRecord::Base.connection.column_exists?(collection.table_name, key)
    result = collection.where("#{key}": value) if collection.present?
    instance_variable_set("@#{collection.first.class.table_name}", result)
  else
    collection
  end
end