Class: Mobility::Backend::Sequel::Serialized::QueryMethods

Inherits:
QueryMethods show all
Defined in:
lib/mobility/backend/sequel/serialized/query_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes, **options) ⇒ QueryMethods

Returns a new instance of QueryMethods.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mobility/backend/sequel/serialized/query_methods.rb', line 4

def initialize(attributes, **options)
  super
  attributes_extractor = @attributes_extractor
  cond_checker = @cond_checker = lambda do |cond|
    if i18n_keys = attributes_extractor.call(cond)
      raise ArgumentError,
        "You cannot query on mobility attributes translated with the Serialized backend (#{i18n_keys.join(", ")})."
    end
  end

  define_method :where do |*cond, &block|
    cond_checker.call(cond.first) || super(*cond, &block)
  end
end