Class: Filterameter::FilterCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/filterameter/filter_coordinator.rb

Overview

# Filter Coordinator

Class FilterCoordinator stores the configuration declared via class-level method calls such as the list of filters and the optionally declared model class. Each controller will have one instance of the coordinator stored as a class variable.

The coordinators encapsulate references to the Query Builder and Filter Registry to keep the namespace clean for controllers that implement filter parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller_name, controller_path) ⇒ FilterCoordinator

Returns a new instance of FilterCoordinator.



25
26
27
28
# File 'lib/filterameter/filter_coordinator.rb', line 25

def initialize(controller_name, controller_path)
  @controller_name = controller_name
  @controller_path = controller_path
end

Instance Attribute Details

#query_variable_nameObject



38
39
40
# File 'lib/filterameter/filter_coordinator.rb', line 38

def query_variable_name
  @query_variable_name ||= model_class.model_name.plural
end

Instance Method Details

#declarations_validatorObject



48
49
50
# File 'lib/filterameter/filter_coordinator.rb', line 48

def declarations_validator
  Filterameter::DeclarationsValidator.new(@controller_name, model_class, registry)
end

#default_sort=(sort_and_direction_pairs) ⇒ Object



42
43
44
45
46
# File 'lib/filterameter/filter_coordinator.rb', line 42

def default_sort=(sort_and_direction_pairs)
  @default_sort = sort_and_direction_pairs.map do |name, direction|
    Filterameter::Helpers::RequestedSort.new(name, direction)
  end
end

#model_class=(model_class) ⇒ Object



30
31
32
# File 'lib/filterameter/filter_coordinator.rb', line 30

def model_class=(model_class)
  @model_class = model_class.is_a?(String) ? model_class.constantize : model_class
end

#query_builderObject



34
35
36
# File 'lib/filterameter/filter_coordinator.rb', line 34

def query_builder
  @query_builder ||= Filterameter::QueryBuilder.new(default_query, @default_sort, registry)
end