Module: ActiveZuora::Scoping::ClassMethods

Defined in:
lib/active_zuora/scoping.rb

Instance Method Summary collapse

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

#relationObject



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

#scopedObject



22
23
24
# File 'lib/active_zuora/scoping.rb', line 22

def scoped
  current_scope || relation
end

#unscopedObject



26
27
28
# File 'lib/active_zuora/scoping.rb', line 26

def unscoped
  block_given? ? relation.scoped { yield } : relation
end