Sha256: 61a0a83ee1c2c06cea95612cec0aea50d5c8672897020117ade73fe352067f94

Contents?: true

Size: 950 Bytes

Versions: 7

Compression:

Stored size: 950 Bytes

Contents

module Mobility
  module Backend
    class ActiveRecord::Serialized::QueryMethods < ActiveRecord::QueryMethods
      def initialize(attributes, **)
        super
        attributes_extractor = @attributes_extractor
        opts_checker = @opts_checker = lambda do |opts|
          if keys = attributes_extractor.call(opts)
            raise ArgumentError,
              "You cannot query on mobility attributes translated with the Serialized backend (#{keys.join(", ")})."
          end
        end

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

      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.model.mobility_where_chain.prepend(mod)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mobility-0.1.12 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.11 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.10 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.7 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.6 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.5 lib/mobility/backend/active_record/serialized/query_methods.rb
mobility-0.1.4 lib/mobility/backend/active_record/serialized/query_methods.rb