Class: Decidim::AdminFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/admin_filter.rb

Overview

This class handles all logic regarding registering filters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AdminFilter

Returns a new instance of AdminFilter.



10
11
12
13
14
15
# File 'lib/decidim/admin_filter.rb', line 10

def initialize(name)
  @name = name
  @filters = []
  @dynamically_translated_filters = []
  @filters_with_values = {}
end

Instance Attribute Details

#dynamically_translated_filtersObject

Returns the value of attribute dynamically_translated_filters.



8
9
10
# File 'lib/decidim/admin_filter.rb', line 8

def dynamically_translated_filters
  @dynamically_translated_filters
end

#filtersObject

Returns the value of attribute filters.



8
9
10
# File 'lib/decidim/admin_filter.rb', line 8

def filters
  @filters
end

#filters_with_valuesObject

Returns the value of attribute filters_with_values.



8
9
10
# File 'lib/decidim/admin_filter.rb', line 8

def filters_with_values
  @filters_with_values
end

Instance Method Details

#add_dynamically_translated_filters(*filters) ⇒ Object



21
22
23
# File 'lib/decidim/admin_filter.rb', line 21

def add_dynamically_translated_filters(*filters)
  @dynamically_translated_filters += filters
end

#add_filters(*filters) ⇒ Object



17
18
19
# File 'lib/decidim/admin_filter.rb', line 17

def add_filters(*filters)
  @filters += filters
end

#add_filters_with_values(**items) ⇒ Object



25
26
27
# File 'lib/decidim/admin_filter.rb', line 25

def add_filters_with_values(**items)
  @filters_with_values.merge!(items)
end

#build_for(context) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/decidim/admin_filter.rb', line 29

def build_for(context)
  raise "Filter #{@name} is not registered" if registry.blank?

  registry.configurations.each do |configuration|
    context.instance_exec(self, &configuration)
  end
  self
end