Module: SimpleScope
- Defined in:
- lib/simple_scope.rb,
lib/simple_scope/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#scope(*args) ⇒ Object
define a simple scope where the conditions are derived from the scope name e.g.
Instance Method Details
#scope(*args) ⇒ Object
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')
7 8 9 10 11 12 13 14 |
# 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 |