lib/timestamp_scopes.rb
def define_timestamp_scope(scope_name, column_name = nil)
      column_name ||= scope_name.to_s + '_at'

      define_singleton_method(scope_name) do |options|
        options ||= {}

        ops = {
          after:  '>',
          before: '<',
        }

        relation = scoped

        options.each do |op, time|
          relation = relation.where("#{column_name} #{ops[op]} ?", time)
        end

        relation
      end

    end
# Add a class method name "scope_name", which handles the before and after
# timestamp scoping DSLs.
Add a class method name "scope_name", which handles the before and after
timestamp scoping DSLs.
Add a class method name " scope_name " which handles the before and after timestamp scoping DSLs .
def define_timestamp_scope(scope_name, column_name = nil)
      column_name ||= scope_name.to_s + '_at'
      define_singleton_method(scope_name) do |options|
        options ||= {}
        ops = {
          after:  '>',
          before: '<',
        }
        relation = scoped
        options.each do |op, time|
          relation = relation.where("#{column_name} #{ops[op]} ?", time)
        end
        relation
      end
    end
def define_timestamp_scope ( scope_name , column_name = nil ) column_name ||= scope_name . to_s + '_at' define_singleton_method ( scope_name ) do | options | options ||= { } ops = { after : '>' , before : '<' , } relation = scoped options . each do | op , time | relation = relation . where ( "#{column_name} #{ops[op]} ?" , time ) end relation end end
Add a class method name "scope_name", which handles the before and after
timestamp scoping DSLs.
Add a class method name " scope_name " which handles the before and after timestamp scoping DSLs .
scope_name
column_name