Class: ContextFilters::Filters::Filters
- Inherits:
-
Object
- Object
- ContextFilters::Filters::Filters
- Includes:
- Store
- Defined in:
- lib/context-filters/filters/filters.rb
Overview
Store and apply filters using blocks
Instance Method Summary collapse
-
#apply(target, method, options = nil) ⇒ Object
applies matching filters to the given target method, also uses filters matching extra :target => target when options is a Hash.
-
#select_filters(target, options) ⇒ Object
Select matching filters and filters including targets when options is a
Hash
.
Methods included from Store
#empty?, #filters, #filters_store, #store
Instance Method Details
#apply(target, method, options = nil) ⇒ Object
applies matching filters to the given target method, also uses filters matching extra :target => target when options is a Hash
46 47 48 |
# File 'lib/context-filters/filters/filters.rb', line 46 def apply(target, method, = nil) select_filters(target, ).each{|block| target.send(method, &block) } end |
#select_filters(target, options) ⇒ Object
Select matching filters and filters including targets when options is a Hash
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/context-filters/filters/filters.rb', line 54 def select_filters(target, ) found = filters_store.fetch(, []) if Hash === || .nil? then ||={} .merge!(:target => target) found += # can not @filters.fetch(options, []) to allow filters provide custom ==() filters_store.select do |, filters| == end.map(&:last).flatten end found end |