Class: Tableficate::Base

Inherits:
Object
  • Object
show all
Extended by:
Finder
Defined in:
lib/tableficate/base.rb

Class Method Summary collapse

Methods included from Finder

tableficate

Class Method Details

.column(name, options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/tableficate/base.rb', line 17

def self.column(name, options = {})
  @sort ||= {}

  @sort[name] = options[:sort] if options[:sort].present?
end

.default_sort(name, dir = 'asc') ⇒ Object



13
14
15
# File 'lib/tableficate/base.rb', line 13

def self.default_sort(name, dir = 'asc')
  @default_sort = [name, dir]
end

.filter(name, options = {}, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tableficate/base.rb', line 23

def self.filter(name, options = {}, &block)
  @filter ||= {}

  if block_given?
    @filter[name] = block
  else
    options.reverse_merge!(
      field: name
    )

    @filter[name] = options
  end
end

.scope(model = nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/tableficate/base.rb', line 5

def self.scope(model = nil)
  if block_given?
    @scope = yield
  else
    @scope = model.to_s.camelize.constantize
  end
end