Class: Filch::Datalist

Inherits:
Object
  • Object
show all
Defined in:
lib/filch/datalist.rb

Overview

Ransack for a datalist

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.arrayify(model, params, column) ⇒ Object

unnest a PostGress Array.



21
22
23
24
# File 'lib/filch/datalist.rb', line 21

def self.arrayify(model, params, column)
  model.ransack(params).result.group(Arel.sql('unnest')).limit(5)
       .pluck(Arel.sql("unnest(#{column})"))
end

.quick(model, column, params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/filch/datalist.rb', line 8

def self.quick(model, column, params)
  col = model.columns_hash[column]
  attrs = model.ransackable_attributes
  if attrs.include?(column) && col.default == '{}'
    arrayify(model, params, column)
  else
    model.ransack(params).result
         .group("#{model.name.pluralize}.#{column}")
         .limit(5).pluck(column)
  end
end

Instance Method Details

#datalist {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



4
5
6
# File 'lib/filch/datalist.rb', line 4

def datalist
  yield self
end