Sha256: 09a75a88dda69dcd181a58e30c8e684cc6b44f9d96f43d1f53542fed52f3026d
Contents?: true
Size: 1007 Bytes
Versions: 16
Compression:
Stored size: 1007 Bytes
Contents
# frozen_string_literal: true module Eac # == Example: # # Note: model Product has a attribute "foo" Date, Time or Number: # # class Product # include ::Eac::InequalityQueries # # add_inequality_queries(:foo) # end # # This add the following scopes: # # Product.by_foo_gt(value) # Equivalent to Product.where("foo > ?", value) # Product.by_foo_gteq(value) # Equivalent to Product.where("foo >= ?", value) # Product.by_foo_lt(value) # Equivalent to Product.where("foo < ?", value) # Product.by_foo_lteq(value) # Equivalent to Product.where("foo <= ?", value) module InequalityQueries class << self def included(base) base.extend(ClassMethods) end end module ClassMethods def add_inequality_queries(attribute) %w(gt gteq lt lteq).each do |ineq| scope "by_#{attribute}_#{ineq}", lambda { |v| where(arel_table[attribute].send(ineq, v)) } end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems