Module: PredicateScope::ClassMethods

Defined in:
lib/predicate_scope.rb

Instance Method Summary collapse

Instance Method Details

#predicate_scope(scope_name, relation_proc) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/predicate_scope.rb', line 37

def predicate_scope(scope_name, relation_proc, ...)
  # Add the scope to the class.
  scope(scope_name, relation_proc, ...)

  # Define the predicate instance method.
  predicate_name = :"#{scope_name}?"
  define_method(predicate_name) do |*predicate_args|
    relation = relation_proc.call(*predicate_args)
    satisfies_conditions_of?(relation)
  end
end