Class: TypeScopes::Numeric

Inherits:
TypeScopes show all
Defined in:
lib/type_scopes/numeric.rb

Constant Summary

Constants inherited from TypeScopes

VERSION

Class Method Summary collapse

Methods inherited from TypeScopes

append_scope, inject, support?

Class Method Details

.inject_for_column(model, name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/type_scopes/numeric.rb', line 6

def self.inject_for_column(model, name)
  column = model.arel_table[name]
  append_scope(model, :"#{name}_to", lambda { |value| where(column.lteq(value)) })
  append_scope(model, :"#{name}_from", lambda { |value| where(column.gteq(value)) })
  append_scope(model, :"#{name}_above", lambda { |value| where(column.gt(value)) })
  append_scope(model, :"#{name}_below", lambda { |value| where(column.lt(value)) })
  append_scope(model, :"#{name}_between", lambda { |from, to| where(name => from..to) })
  append_scope(model, :"#{name}_not_between", lambda { |from, to| where.not(name => from..to) })
  append_scope(model, :"#{name}_within", lambda { |from, to| where(column.gt(from)).where(column.lt(to)) })
  append_scope(model, :"#{name}_not_within", lambda { |from, to| where(column.lteq(from).or(column.gteq(to))) })
end

.typesObject



2
3
4
# File 'lib/type_scopes/numeric.rb', line 2

def self.types
  ["integer", "double precision", "numeric", "bigint", "decimal"].freeze
end