Module: WildcardScopes::Base::ClassMethods
- Defined in:
- lib/wildcard_scopes/base.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/wildcard_scopes/base.rb', line 15
def method_missing(method, *args, &block)
super if self.wildcard_scopes.blank?
self.wildcard_scopes.each do |name, scope_params|
matchdata = name.match(method.to_s)
if matchdata
self.class_eval do
scope method.to_sym, self.instance_exec(matchdata.to_a.slice(1..-1), &scope_params.first)
end
return self.send(method)
end
end
super
end
|
Instance Method Details
#wildcard_scope(name_regex, *args) ⇒ Object
10
11
12
13
|
# File 'lib/wildcard_scopes/base.rb', line 10
def wildcard_scope(name_regex, *args)
self.wildcard_scopes ||= {}
self.wildcard_scopes[name_regex] = args
end
|