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
75 76 77 78 79 |
# File 'lib/active_admin/filters/resource_extension.rb', line 75 def add_filter(attribute, = {}) raise Disabled, "add" 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
37 38 39 |
# File 'lib/active_admin/filters/resource_extension.rb', line 37 def current_filters=(bool) @current_filters_enabled = bool end |
#current_filters_enabled? ⇒ Boolean
Returns If show current filters are enabled for this resource.
47 48 49 |
# File 'lib/active_admin/filters/resource_extension.rb', line 47 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.
23 24 25 |
# File 'lib/active_admin/filters/resource_extension.rb', line 23 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
30 31 32 |
# File 'lib/active_admin/filters/resource_extension.rb', line 30 def filters=(bool) @filters_enabled = bool end |
#filters_enabled? ⇒ Boolean
Returns If filters are enabled for this resource.
42 43 44 |
# File 'lib/active_admin/filters/resource_extension.rb', line 42 def filters_enabled? @filters_enabled.nil? ? namespace.filters : @filters_enabled end |
#initialize ⇒ Object
13 14 15 16 17 |
# File 'lib/active_admin/filters/resource_extension.rb', line 13 def initialize(*) super end |
#preserve_default_filters! ⇒ Object
51 52 53 |
# File 'lib/active_admin/filters/resource_extension.rb', line 51 def preserve_default_filters! @preserve_default_filters = true end |
#preserve_default_filters? ⇒ Boolean
55 56 57 |
# File 'lib/active_admin/filters/resource_extension.rb', line 55 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
63 64 65 66 67 |
# File 'lib/active_admin/filters/resource_extension.rb', line 63 def remove_filter(*attributes) raise Disabled, "remove" unless filters_enabled? attributes.each { |attribute| (@filters_to_remove ||= []) << attribute.to_sym } end |
#reset_filters! ⇒ Object
Reset the filters to use defaults
82 83 84 85 |
# File 'lib/active_admin/filters/resource_extension.rb', line 82 def reset_filters! @filters = nil @filters_to_remove = nil end |