Module: SimpleColumn
- Defined in:
- lib/simple_column/scopes.rb,
lib/simple_column/scopes/version.rb
Overview
Purpose: Create dynamic modules which define dynamic methods for scopes based on a dynamic array of column names
Library Usage:
class Monkey < ActiveRecord::Base
include SimpleColumn::Scopes.new(:for_user_id, :for_seller_id, ... etc)
# => for_user_id, and for_seller_id scopes are added to the model,
and they query on the user_id and seller_id columns, respectively
Defined Under Namespace
Classes: Scopes
Constant Summary collapse
- SCOPE_PREFIX =
'for_'.freeze
- SCOPE_PREFIX_REGEX =
Regexp.new("\\A#{SimpleColumn::SCOPE_PREFIX}")
Class Method Summary collapse
-
.to_mod(scope_names_hash) ⇒ Object
returns an anonymous (nameless) Module instance.
Class Method Details
.to_mod(scope_names_hash) ⇒ Object
returns an anonymous (nameless) Module instance
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/simple_column/scopes.rb', line 20 def to_mod(scope_names_hash) Module.new do scope_names_hash.each do |scope_name, column_name| # methods are defined at the instance level, so will become class methods when this module extends a class. define_method(scope_name) do |value| where(column_name => value) end end end end |