Module: Katsudo::Scopes

Included in:
Models::Activity::ClassMethods
Defined in:
lib/katsudo/models/scopes.rb

Instance Method Summary collapse

Instance Method Details

#fetch(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/katsudo/models/scopes.rb', line 4

def fetch(*args)
  options = args.extract_options!
  conditions = {}
  if args.first
    conditions[:type] = args.first.to_s.classify
  end
  if options[:resource]
    conditions[:resource_type] = options[:resource].class.name
    conditions[:resource_id] = options[:resource].id
  end
  if options[:user]
    conditions[:user_type] = options[:user].class.name
    conditions[:user_id] = options[:user].id
  end
  where(conditions)
end