Class: Outpost::List::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/outpost/list/filter.rb

Constant Summary collapse

BOOLEAN_COLLECT =
[["Yes", 1], ["No", 0]]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, list, options = {}) ⇒ Filter

Returns a new instance of Filter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/outpost/list/filter.rb', line 11

def initialize(attribute, list, options={})
  @attribute  = attribute.to_s
  @list       = list
  @title      = options[:title] || @attribute.titleize

  collection = options[:collection]
  @collection = begin
    case collection
    when NilClass # No collection given. Find it ourselves.
      if list.model.column_names.include?(@attribute)
        -> {
          list.model.order(@attribute).pluck("distinct #{@attribute}")
        }
      else
        # TODO Handle association filtering
      end
    when Proc
      collection
    when Symbol
      send "_#{collection}_collection"
    end
  end
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



9
10
11
# File 'lib/outpost/list/filter.rb', line 9

def attribute
  @attribute
end

#collectionObject

Returns the value of attribute collection.



9
10
11
# File 'lib/outpost/list/filter.rb', line 9

def collection
  @collection
end

#listObject

Returns the value of attribute list.



9
10
11
# File 'lib/outpost/list/filter.rb', line 9

def list
  @list
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/outpost/list/filter.rb', line 9

def title
  @title
end