summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-02-20 20:48:56 -0700
committermo khan <mo@mokhan.ca>2014-02-20 20:48:56 -0700
commit676c9df5c6da3f60fd8f1a6184810acff5d74df9 (patch)
tree684f9b6258bb57f51c0fa27b24d15fd9d1d66fb6
parentbd442141974a110a1647b01be919bf03de407ab9 (diff)
extract search filter method.
-rw-r--r--app/controllers/v1/company_licenses_controller.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/controllers/v1/company_licenses_controller.rb b/app/controllers/v1/company_licenses_controller.rb
index 963423a..32e3bc1 100644
--- a/app/controllers/v1/company_licenses_controller.rb
+++ b/app/controllers/v1/company_licenses_controller.rb
@@ -2,13 +2,22 @@ class V1::CompanyLicensesController < ApplicationController
before_filter :load_company
def index
- @active_licenses = @company.status(LicenseStatus::ACTIVE)
- @active_licenses = @active_licenses.township(params[:township]) if params[:township].present?
+ @active_licenses = filter_using(@company, search_filters)
render json: @active_licenses
end
private
+ def search_filters
+ { status: LicenseStatus::ACTIVE, township: params[:township] }
+ end
+
+ def filter_using(scope, filters)
+ result = scope
+ filters.each { |key, value| result = result.public_send(key, value) if value.present? }
+ result
+ end
+
def load_company
@company = Company.find(params[:company_id])
end