This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CreatedAtScopes | |
extend ActiveSupport::Concern | |
# Lambda does not pollute a class namespace but do the job. | |
tz_time_today = -> { Time.zone.now.beginning_of_day } | |
included do | |
scope :created_before, ->(time) { where(arel_table[:created_at].lt(time)) } | |
scope :created_after, ->(time) { where(arel_table[:created_at].gt(time)) } | |
scope :created_today, -> { created_after(tz_time_today[]) } | |
scope :created_yesterday, -> { created_after(tz_time_today[] - 1.day).created_before(tz_time_today[]) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |