Class: Mobility::Backends::ActiveRecord::Serialized::QueryMethods

Inherits:
QueryMethods
  • Object
show all
Defined in:
lib/mobility/backends/active_record/serialized/query_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes, _) ⇒ QueryMethods

Returns a new instance of QueryMethods.



6
7
8
9
10
11
12
13
14
# File 'lib/mobility/backends/active_record/serialized/query_methods.rb', line 6

def initialize(attributes, _)
  super
  attributes_extractor = @attributes_extractor
  opts_checker = @opts_checker = Backends::Serialized.attr_checker(attributes_extractor)

  define_method :where! do |opts, *rest|
    opts_checker.call(opts) || super(opts, *rest)
  end
end

Instance Method Details

#extended(relation) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mobility/backends/active_record/serialized/query_methods.rb', line 16

def extended(relation)
  super
  opts_checker = @opts_checker

  mod = Module.new do
    define_method :not do |opts, *rest|
      opts_checker.call(opts) || super(opts, *rest)
    end
  end
  relation.mobility_where_chain.include(mod)
end