Module: ActiveZuora::Scoping::ClassMethods
- Defined in:
- lib/active_zuora/scoping.rb
Instance Method Summary collapse
- #exclude_from_queries(*field_names) ⇒ Object
- #relation ⇒ Object
- #scope(name, body) ⇒ Object
- #scoped ⇒ Object
- #unscoped ⇒ Object
Instance Method Details
#exclude_from_queries(*field_names) ⇒ Object
30 31 32 |
# File 'lib/active_zuora/scoping.rb', line 30 def exclude_from_queries(*field_names) (@excluded_from_queries ||= []).concat field_names.map(&:to_sym) end |
#relation ⇒ Object
34 35 36 37 |
# File 'lib/active_zuora/scoping.rb', line 34 def relation query_field_names = field_names - (@excluded_from_queries ||= []) Relation.new(self, query_field_names) end |
#scope(name, body) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/active_zuora/scoping.rb', line 39 def scope(name, body) # Body can be a Relation or a lambda that returns a relation. define_singleton_method(name) do |*args| body.respond_to?(:call) ? body.call(*args) : scoped.merge(body) end end |
#scoped ⇒ Object
22 23 24 |
# File 'lib/active_zuora/scoping.rb', line 22 def scoped current_scope || relation end |
#unscoped ⇒ Object
26 27 28 |
# File 'lib/active_zuora/scoping.rb', line 26 def unscoped block_given? ? relation.scoped { yield } : relation end |