@@ -73,9 +73,11 @@ def __create_jsonb_typed_scopes(jsonb_attribute, fields_map)
7373 when :boolean
7474 ___create_jsonb_boolean_scopes ( field )
7575 when :integer , :float , :decimal , :big_integer
76- ___create_jsonb_numeric_scopes ( field , type , jsonb_attribute )
76+ ___create_jsonb_numeric_scopes ( field , jsonb_attribute , type )
7777 when :date_time , :date , :time
7878 ___create_jsonb_date_time_scopes ( field , jsonb_attribute , type )
79+ when /array/
80+ ___create_jsonb_array_scopes ( field )
7981 end
8082 end
8183 end
@@ -85,9 +87,9 @@ def ___create_jsonb_boolean_scopes(field)
8587 scope "not_#{ field } " , -> { send ( "with_#{ field } " , false ) }
8688 end
8789
88- def ___create_jsonb_numeric_scopes ( field , type , jsonb_attribute )
90+ def ___create_jsonb_numeric_scopes ( field , jsonb_attribute , type )
8991 safe_type = type . to_s . gsub ( "big_" , "" )
90- scope "__numeric_#{ field } _comparator" , -> ( value , operator ) { where ( "((#{ table_name } .#{ jsonb_attribute } ) ->> ?)::#{ safe_type } #{ operator } ?" , field , value ) }
92+ scope "__numeric_#{ field } _comparator" , -> ( value , operator ) { where ( "((#{ table_name } .#{ jsonb_attribute } ) - >> ?)::#{ safe_type } #{ operator } ?" , field , value ) }
9193 scope "#{ field } _lt" , -> ( value ) { send ( "__numeric_#{ field } _comparator" , value , "<" ) }
9294 scope "#{ field } _lte" , -> ( value ) { send ( "__numeric_#{ field } _comparator" , value , "<=" ) }
9395 scope "#{ field } _gte" , -> ( value ) { send ( "__numeric_#{ field } _comparator" , value , ">=" ) }
@@ -98,6 +100,10 @@ def ___create_jsonb_date_time_scopes(field, jsonb_attribute, type)
98100 scope "#{ field } _before" , -> ( value ) { where ( "((#{ table_name } .#{ jsonb_attribute } ) ->> ?)::timestamp < ?::timestamp" , field , value . to_json ) }
99101 end
100102
103+ def ___create_jsonb_array_scopes ( field )
104+ scope "#{ field } _contains" , -> ( value ) { send ( "with_#{ field } " , [ value ] ) }
105+ end
106+
101107 def _create_jsonb_accessor_methods ( jsonb_attribute , jsonb_attribute_initialization_method_name , fields_map )
102108 jsonb_accessor_methods = Module . new do
103109 define_method ( "#{ jsonb_attribute } =" ) do |value |
0 commit comments