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

@@ -171,6 +171,10 @@ class Dmail < ApplicationRecord
end
end
def read
where(is_read: true)
end
def unread
where("is_read = false and is_deleted = false")
end
@@ -220,11 +224,8 @@ class Dmail < ApplicationRecord
q = q.where("is_spam = ?", false)
end
if params[:read] == "true"
q = q.where("is_read = true")
elsif params[:read] == "false"
q = q.unread
end
q = q.read if params[:read].to_s.truthy?
q = q.unread if params[:read].to_s.falsy?
q.apply_default_order(params)
end