Class: TinyFilter::Base
- Inherits:
-
Object
- Object
- TinyFilter::Base
- Defined in:
- lib/tiny_filter/base.rb
Class Method Summary collapse
- .filter(base_scope, args = {}) ⇒ Object
- .filters(key, &block) ⇒ Object
- .inherited(subclass) ⇒ Object
Class Method Details
.filter(base_scope, args = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/tiny_filter/base.rb', line 16 def filter(base_scope, args = {}) args.inject(base_scope) do |scope, (key, value)| key = key.to_sym raise NotDefinedError, "unable to find filter :#{key} in #{self}" unless __filters__.key?(key) __filters__[key].call(scope, value) end end |
.filters(key, &block) ⇒ Object
12 13 14 |
# File 'lib/tiny_filter/base.rb', line 12 def filters(key, &block) __filters__[key.to_sym] = block end |
.inherited(subclass) ⇒ Object
6 7 8 9 10 |
# File 'lib/tiny_filter/base.rb', line 6 def inherited(subclass) super dup_filters = __filters__.dup subclass.__filters__ = dup_filters.each { |key, value| dup_filters[key] = value.dup } end |