String: add truthy? & falsy? core extensions.

* Add `truthy?` and `falsy?` core extensions to String.

* Use `truthy?` and `falsy?` to replace ad-hoc parsing of boolean
  parameters in various places.
This commit is contained in:
evazion
2018-05-03 18:53:35 -05:00
parent 96669ca4b5
commit c7492343ce
15 changed files with 62 additions and 102 deletions

View File

@@ -587,13 +587,13 @@ class Artist < ApplicationRecord
end
# XXX deprecated, remove at some point.
if params[:empty_only] == "true"
if params[:empty_only].to_s.truthy?
params[:has_tag] = "false"
end
if params[:has_tag] == "true"
if params[:has_tag].to_s.truthy?
q = q.joins(:tag).where("tags.post_count > 0")
elsif params[:has_tag] == "false"
elsif params[:has_tag].to_s.falsy?
q = q.includes(:tag).where("tags.name IS NULL OR tags.post_count <= 0").references(:tags)
end