class ActiveFacet::Filter
Public Class Methods
Register queued filters for given resource class @param receiver [Class] resource class @return [Class] for chaining
# File lib/active_facet/filter.rb, line 35 def self.apply_globals_to(receiver) raise ActiveFacet::Errors::ConfigurationError.new(ActiveFacet::Errors::ConfigurationError::ACTS_AS_ERROR_MSG) unless filterable?(receiver) global_filters.each do |filter_name, filter_method| filter_method_name = receiver.acts_as_active_facet_options[:filter_method_name] receiver.send(filter_method_name, filter_name, filter_method) end receiver end
Tells if any filters can be registered for the given resource class @return [Boolean]
# File lib/active_facet/filter.rb, line 58 def self.filterable?(receiver) receiver.ancestors.include? ActiveFacet::ActsAsActiveFacet end
Tells that the receiver class implements a filter @param receiver [Class] resource class @param filter_name [Symbol] @param filter_method_name [Symbol] name of method defined on receiver instances which implments the filter @return [Class] for chaining
# File lib/active_facet/filter.rb, line 25 def self.register(receiver, filter_name, filter_method_name) raise ActiveFacet::Errors::ConfigurationError.new(ActiveFacet::Errors::ConfigurationError::ACTS_AS_ERROR_MSG) unless filterable?(receiver) receiver_filters = filters[receiver.name] ||= {} receiver_filters[filter_name.to_sym] = filter_method_name.to_sym receiver end
Queues a filter to be applied to resource classes @param filter_name [Symbol] @param filter_method [Proc] method body code which implements the filter @return [Proc] for chaining
# File lib/active_facet/filter.rb, line 16 def self.register_global(filter_name, filter_method) global_filters[filter_name.to_sym] = filter_method end
Returns the list of filters the resource class implements Memoized @param receiver [Class] resource class @return [Hash] all filters registered on this resource (and superclass)
# File lib/active_facet/filter.rb, line 48 def self.registered_filters_for(receiver) registered_filters[receiver.name] ||= begin receiver_filters = filters[receiver.name] ||= {} receiver_filters.reverse_merge!(registered_filters_for(receiver.superclass)) if filterable?(receiver.superclass) receiver_filters end end