config/initializers/wrappers/scopes/default_scopes.rb in eitil-0.3.1 vs config/initializers/wrappers/scopes/default_scopes.rb in eitil-0.3.2

- old
+ new

@@ -9,23 +9,32 @@ eitil_scope :"#{column}_future", -> { where("#{column} > ?", Date.today) } eitil_scope :"#{column}_on_date", -> (date) { where("#{column} = ?", date) } eitil_scope :"#{column}_before_date", -> (date) { where("#{column} = ?", date) } eitil_scope :"#{column}_after_date", -> (date) { where("#{column} = ?", date) } - eitil_scope :"#{column}_between_dates", -> (from, till) { where("#{column} >= ? and #{column} <= ?", from, till) } eitil_scope :"#{column}_oldest_first", -> { order("#{column} ASC") } eitil_scope :"#{column}_newest_first", -> { order("#{column} DESC") } } + SharableNumScopes = -> (column) { + eitil_scope :"#{column}_equal_to", -> (number) { where("#{column} = ?", number) } + eitil_scope :"#{column}_lower_than", -> (number) { where("#{column} = <", number) } + eitil_scope :"#{column}_higher_than", -> (number) { where("#{column} = >", number) } + eitil_scope :"#{column}_between", -> (min, max) { where("#{column} >= ? and #{column} <= ?", min, max) } + + eitil_scope :"#{column}_ascending", -> { order("#{column} ASC") } + eitil_scope :"#{column}_descending", -> { order("#{column} DESC") } + } + class << self private def use_eitil_scopes - %i[boolean datetime date].each { |_type| send :"create_eitil_#{_type}_scopes" } + %i[boolean datetime date integer float].each { |_type| send :"create_eitil_#{_type}_scopes" } end def eitil_scope(_name, _proc) scope _name, _proc unless respond_to? _name end @@ -48,9 +57,21 @@ end def create_eitil_date_scopes columns_of_type(:date).map do |column, object| SharableDateScopes.call column + end + end + + def create_eitil_integer_scopes + columns_of_type(:integer).map do |column, object| + SharableNumScopes.call column + end + end + + def create_eitil_float_scopes + columns_of_type(:float).map do |column, object| + SharableNumScopes.call column end end end \ No newline at end of file