Module: Perry::Modifiers
- Defined in:
- lib/perry/relation/modifiers.rb
Instance Attribute Summary collapse
-
#modifiers_array ⇒ Object
Returns the value of attribute modifiers_array.
-
#modifiers_value ⇒ Object
Returns the value of attribute modifiers_value.
Instance Method Summary collapse
-
#modifiers(value = {}) ⇒ Object
The modifiers query method allows you to ‘extend’ your query by adding parameters that middlewares or adapters can use to modify the query itself or modify how the query is executed.
Instance Attribute Details
#modifiers_array ⇒ Object
Returns the value of attribute modifiers_array.
2 3 4 |
# File 'lib/perry/relation/modifiers.rb', line 2 def modifiers_array @modifiers_array end |
#modifiers_value ⇒ Object
Returns the value of attribute modifiers_value.
2 3 4 |
# File 'lib/perry/relation/modifiers.rb', line 2 def modifiers_value @modifiers_value end |
Instance Method Details
#modifiers(value = {}) ⇒ Object
The modifiers query method allows you to ‘extend’ your query by adding parameters that middlewares or adapters can use to modify the query itself or modify how the query is executed. This method expects a hash or a Proc that returns a hash as its only argument and will merge that hash onto a master hash of query modifiers.
For most purposes, the modifiers method acts like any other query method. For example, you can chain it with other query methods on a relation, and you can build scopes with it. One exception is that modifiers are not included in the hash returned by Relation#to_hash. This exception is intended to discourage adapters from passing modifiers to backends external to perry (such as a data server or a webservice call) whose behavior is undefined with respect to these additional parameters/
See also ‘perry/middlewares/cache_records/scopes.rb’ for examples of how to use the modifiers pseudo-query method.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/perry/relation/modifiers.rb', line 18 def modifiers(value={}) clone.tap do |r| if value.nil? r.modifiers_array = [] # wipeout all previously set modifiers else r.modifiers_array ||= [] r.modifiers_array.push(value) end end end |