Module: ActiveRecord::Extension::WithScope

Defined in:
lib/vex/active_record/with_scope.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
6
7
# File 'lib/vex/active_record/with_scope.rb', line 3

def self.included(klass)
  #
  # add a custom scope. 
  klass.named_scope :with, lambda { |*args| ActiveRecord::Extension::WithScope.options(*args) }
end

.options(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vex/active_record/with_scope.rb', line 9

def self.options(*args)
  options = args.extract_options!
  if options[:conditions] && !args.empty?
    raise "Cannot have multiple condition entries"
  end

  unless args.empty?
    options = { :conditions => args }.update(options)
  end

  options
end