Class: Datagrid::Filters::BaseFilter
- Inherits:
-
Object
- Object
- Datagrid::Filters::BaseFilter
show all
- Defined in:
- lib/datagrid/filters/base_filter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(grid, name, options = {}, &block) ⇒ BaseFilter
Returns a new instance of BaseFilter.
7
8
9
10
11
12
|
# File 'lib/datagrid/filters/base_filter.rb', line 7
def initialize(grid, name, options = {}, &block)
self.grid = grid
self.name = name
self.options = options
self.block = block
end
|
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
5
6
7
|
# File 'lib/datagrid/filters/base_filter.rb', line 5
def block
@block
end
|
#grid ⇒ Object
Returns the value of attribute grid.
5
6
7
|
# File 'lib/datagrid/filters/base_filter.rb', line 5
def grid
@grid
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/datagrid/filters/base_filter.rb', line 5
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/datagrid/filters/base_filter.rb', line 5
def options
@options
end
|
Instance Method Details
#allow_blank? ⇒ Boolean
56
57
58
|
# File 'lib/datagrid/filters/base_filter.rb', line 56
def allow_blank?
options[:allow_blank]
end
|
#allow_nil? ⇒ Boolean
52
53
54
|
# File 'lib/datagrid/filters/base_filter.rb', line 52
def allow_nil?
options.has_key?(:allow_nil) ? options[:allow_nil] : options[:allow_blank]
end
|
#apply(scope, value) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/datagrid/filters/base_filter.rb', line 18
def apply(scope, value)
if value.nil?
return scope if !allow_nil?
else
return scope if value.blank? && !allow_blank?
end
::Datagrid::Filters::FilterEval.new(self, scope, value).run
end
|
#default ⇒ Object
43
44
45
46
|
# File 'lib/datagrid/filters/base_filter.rb', line 43
def default
default = self.options[:default]
default.respond_to?(:call) ? default.call : default
end
|
14
15
16
|
# File 'lib/datagrid/filters/base_filter.rb', line 14
def format(value)
raise NotImplementedError, "#format(value) suppose to be overwritten"
end
|
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/datagrid/filters/base_filter.rb', line 27
def format_values(value)
if !self.multiple && value.is_a?(Array)
raise Datagrid::ArgumentError, "#{grid.class}.#{name} filter can not accept Array argument. Use :multiple option."
end
values = Array.wrap(value)
values.map! do |value|
self.format(value)
end
self.multiple ? values : values.first
end
|
38
39
40
41
|
# File 'lib/datagrid/filters/base_filter.rb', line 38
def
options[:header] ||
I18n.translate(self.name, :scope => "datagrid.#{grid.param_name}.filters", :default => self.name.to_s.humanize)
end
|
#multiple ⇒ Object
48
49
50
|
# File 'lib/datagrid/filters/base_filter.rb', line 48
def multiple
self.options[:multiple]
end
|