Class: Mobility::Backend::ActiveRecord::Serialized::QueryMethods
- Inherits:
-
QueryMethods
- Object
- Module
- QueryMethods
- Mobility::Backend::ActiveRecord::Serialized::QueryMethods
- Defined in:
- lib/mobility/backend/active_record/serialized/query_methods.rb
Instance Method Summary collapse
- #extended(relation) ⇒ Object
-
#initialize(attributes, **options) ⇒ QueryMethods
constructor
A new instance of QueryMethods.
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/active_record/serialized/query_methods.rb', line 4 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 |
Instance Method Details
#extended(relation) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mobility/backend/active_record/serialized/query_methods.rb', line 19 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 |