Class: Tablets::Tablet

Inherits:
Object
  • Object
show all
Defined in:
lib/tablets/tablet.rb

Overview

Incapsulates tablet related information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Tablet

Initializes tablet with name, callbacks fed with block



9
10
11
12
# File 'lib/tablets/tablet.rb', line 9

def initialize(name, &block)
  @name = name
  @config = Tablets::Utils::Config.new(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/tablets/tablet.rb', line 6

def name
  @name
end

Instance Method Details

#authorize(controller) ⇒ Object

Determines is user authorized By default returns true



22
23
24
# File 'lib/tablets/tablet.rb', line 22

def authorize(controller)
  call(:authorize, controller) { true }
end

#columnsObject

Returns columns definitions By default deduct columns from relation



40
41
42
# File 'lib/tablets/tablet.rb', line 40

def columns
  call(:columns) { deduct_columns_from_relation }
end

#details(record) ⇒ Object

Returns details HTML for the record By default returns nil



34
35
36
# File 'lib/tablets/tablet.rb', line 34

def details(record)
  call(:details, record) { nil }
end

#has?(name) ⇒ Boolean

Checks if config has callback with specified name

Returns:

  • (Boolean)


62
63
64
# File 'lib/tablets/tablet.rb', line 62

def has?(name)
  @config.has?(name)
end

#optionsObject

Returns general jquery-datatable configuration overrides By default returns empty options



16
17
18
# File 'lib/tablets/tablet.rb', line 16

def options
  call(:options) { {} }
end

#payloadObject

Returns additional data returned to client



57
58
59
# File 'lib/tablets/tablet.rb', line 57

def payload
  call(:payload) { {} }
end

#process(records) ⇒ Object

Allows to make additional processing before records would be used By default returns records



28
29
30
# File 'lib/tablets/tablet.rb', line 28

def process(records)
  call(:process, records) { records }
end

#relation(params = {}, controller = nil) ⇒ Object

Returns database relation to fetch data By default tries to deduct class from tablet name



46
47
48
49
50
51
52
53
54
# File 'lib/tablets/tablet.rb', line 46

def relation(params = {}, controller = nil)
  if defined? @name.singularize.camelize.constantize
    call(:relation, params, controller) do
      @name.camelize.constantize.where(nil)
    end
  else
    call(:relation, params, controller)
  end
end