Class: Mobility::Backend::ActiveRecord::QueryMethods
- Defined in:
- lib/mobility/backend/active_record/query_methods.rb
Overview
Defines query method overrides to handle translated attributes for ActiveRecord models. For details see backend-specific subclasses.
Direct Known Subclasses
Column::QueryMethods, Hstore::QueryMethods, Jsonb::QueryMethods, KeyValue::QueryMethods, Serialized::QueryMethods, Table::QueryMethods
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.
13 14 15 16 17 18 |
# File 'lib/mobility/backend/active_record/query_methods.rb', line 13 def initialize(attributes, **) @attributes = attributes @attributes_extractor = lambda do |opts| opts.is_a?(Hash) && (opts.keys.map(&:to_s) & attributes).presence end end |
Instance Method Details
#extended(relation) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mobility/backend/active_record/query_methods.rb', line 21 def extended(relation) model_class = relation.model unless model_class.respond_to?(:mobility_where_chain) model_class.define_singleton_method(:mobility_where_chain) do @mobility_where_chain ||= Class.new(::ActiveRecord::QueryMethods::WhereChain) end relation.define_singleton_method :where do |opts = :chain, *rest| opts == :chain ? mobility_where_chain.new(spawn) : super(opts, *rest) end end end |