module SimpleScope

Constants

VERSION

Public Instance Methods

scope(*args) click to toggle source

define a simple scope where the conditions are derived from the scope name e.g. scope :color_red # => where('color' => 'red')

scope :name_bob_and_role_admin # => where('name' => 'bob', 'role' => 'admin')
Calls superclass method
# File lib/simple_scope.rb, line 7
def scope(*args)
  return super if args.size > 1
  
  pairs = args.first.to_s.split '_and_'
  conditions = Hash[pairs.map { |p| p.split('_') }]

  super args.first, -> { where conditions }
end