Class: Zadok::Filters::Ransack::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/zadok/filters/ransack/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
# File 'lib/zadok/filters/ransack/base.rb', line 7

def initialize(opts = {})
  @params = opts[:params]
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/zadok/filters/ransack/base.rb', line 11

def params
  @params
end

Instance Method Details

#active_in?(current_params) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/zadok/filters/ransack/base.rb', line 18

def active_in?(current_params)
  params.any? { |param| current_params.include? param }
end

#add_to_params(current_params, value) ⇒ Object



62
63
64
# File 'lib/zadok/filters/ransack/base.rb', line 62

def add_to_params(current_params, value)
  current_params.merge(param => value)
end

#describe(_current_params) ⇒ Object

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/zadok/filters/ransack/base.rb', line 34

def describe(_current_params)
  raise NotImplementedError
end

#i18n_nameObject



26
27
28
# File 'lib/zadok/filters/ransack/base.rb', line 26

def i18n_name
  I18n.t("filter.#{self.class.name.split('::').last.underscore}")
end

#indexObject



22
23
24
# File 'lib/zadok/filters/ransack/base.rb', line 22

def index
  99
end

#modify_columns(columns) ⇒ Object

Each filter may opt to change the column(s) of the filtered admission list table - add or remove some.



54
55
56
# File 'lib/zadok/filters/ransack/base.rb', line 54

def modify_columns(columns)
  columns
end

#optionsObject

options hash for filters with options



48
49
50
# File 'lib/zadok/filters/ransack/base.rb', line 48

def options
  I18n.t("filter_labels.#{param}").with_indifferent_access
end

#paramObject

most filters just use a single param



14
15
16
# File 'lib/zadok/filters/ransack/base.rb', line 14

def param
  params[0]
end

#remove_from_params(current_params) ⇒ Object



58
59
60
# File 'lib/zadok/filters/ransack/base.rb', line 58

def remove_from_params(current_params)
  current_params.except(*params)
end

#text(_current_params) ⇒ Object



43
44
45
# File 'lib/zadok/filters/ransack/base.rb', line 43

def text(_current_params)
  param
end

#titleObject



30
31
32
# File 'lib/zadok/filters/ransack/base.rb', line 30

def title
  i18n_name
end

#typeObject

form control type

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/zadok/filters/ransack/base.rb', line 39

def type
  raise NotImplementedError
end