Module: ActiveAdmin::Filters::ResourceExtension
- Defined in:
- lib/active_admin/filters/resource_extension.rb
Instance Method Summary collapse
-
#add_filter(attribute, options = {}) ⇒ Object
Add a filter for this resource.
-
#current_filters=(bool) ⇒ Object
Setter to enable/disable showing current filters on this resource.
-
#current_filters_enabled? ⇒ Boolean
If show current filters are enabled for this resource.
-
#filters ⇒ Hash
Returns the filters for this resource.
-
#filters=(bool) ⇒ Object
Setter to enable / disable filters on this resource.
-
#filters_enabled? ⇒ Boolean
If filters are enabled for this resource.
- #initialize ⇒ Object
- #preserve_default_filters! ⇒ Object
- #preserve_default_filters? ⇒ Boolean
-
#remove_filter(*attributes) ⇒ Object
Remove a filter for this resource.
-
#reset_filters! ⇒ Object
Reset the filters to use defaults.
Instance Method Details
#add_filter(attribute, options = {}) ⇒ Object
Add a filter for this resource. If filters are not enabled, this method will raise a RuntimeError
76 77 78 79 80 |
# File 'lib/active_admin/filters/resource_extension.rb', line 76 def add_filter(attribute, = {}) raise Disabled unless filters_enabled? (@filters ||= {})[attribute.to_sym] = end |
#current_filters=(bool) ⇒ Object
Setter to enable/disable showing current filters on this resource.
Set to ‘nil` to inherit the setting from the namespace
38 39 40 |
# File 'lib/active_admin/filters/resource_extension.rb', line 38 def current_filters=(bool) @current_filters_enabled = bool end |
#current_filters_enabled? ⇒ Boolean
Returns If show current filters are enabled for this resource.
48 49 50 |
# File 'lib/active_admin/filters/resource_extension.rb', line 48 def current_filters_enabled? @current_filters_enabled.nil? ? namespace.current_filters : @current_filters_enabled end |
#filters ⇒ Hash
Returns the filters for this resource. If filters are not enabled, it will always return an empty hash.
24 25 26 |
# File 'lib/active_admin/filters/resource_extension.rb', line 24 def filters filters_enabled? ? filter_lookup : {} end |
#filters=(bool) ⇒ Object
Setter to enable / disable filters on this resource.
Set to ‘nil` to inherit the setting from the namespace
31 32 33 |
# File 'lib/active_admin/filters/resource_extension.rb', line 31 def filters=(bool) @filters_enabled = bool end |
#filters_enabled? ⇒ Boolean
Returns If filters are enabled for this resource.
43 44 45 |
# File 'lib/active_admin/filters/resource_extension.rb', line 43 def filters_enabled? @filters_enabled.nil? ? namespace.filters : @filters_enabled end |
#initialize ⇒ Object
14 15 16 17 18 |
# File 'lib/active_admin/filters/resource_extension.rb', line 14 def initialize(*) super end |
#preserve_default_filters! ⇒ Object
52 53 54 |
# File 'lib/active_admin/filters/resource_extension.rb', line 52 def preserve_default_filters! @preserve_default_filters = true end |
#preserve_default_filters? ⇒ Boolean
56 57 58 |
# File 'lib/active_admin/filters/resource_extension.rb', line 56 def preserve_default_filters? @preserve_default_filters == true end |
#remove_filter(*attributes) ⇒ Object
Remove a filter for this resource. If filters are not enabled, this method will raise a RuntimeError
64 65 66 67 68 |
# File 'lib/active_admin/filters/resource_extension.rb', line 64 def remove_filter(*attributes) raise Disabled unless filters_enabled? attributes.each { |attribute| (@filters_to_remove ||= []) << attribute.to_sym } end |
#reset_filters! ⇒ Object
Reset the filters to use defaults
83 84 85 86 |
# File 'lib/active_admin/filters/resource_extension.rb', line 83 def reset_filters! @filters = nil @filters_to_remove = nil end |