Class: Tablets::Tablet
- Inherits:
-
Object
- Object
- Tablets::Tablet
- Defined in:
- lib/tablets/tablet.rb
Overview
Incapsulates tablet related information
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#authorize(controller) ⇒ Object
Determines is user authorized By default returns true.
-
#columns ⇒ Object
Returns columns definitions By default deduct columns from relation.
-
#details(record) ⇒ Object
Returns details HTML for the record By default returns nil.
-
#has?(name) ⇒ Boolean
Checks if config has callback with specified name.
-
#initialize(name, &block) ⇒ Tablet
constructor
Initializes tablet with name, callbacks fed with block.
-
#options ⇒ Object
Returns general jquery-datatable configuration overrides By default returns empty options.
-
#payload ⇒ Object
Returns additional data returned to client.
-
#process(records) ⇒ Object
Allows to make additional processing before records would be used By default returns records.
-
#relation(params = {}, controller = nil) ⇒ Object
Returns database relation to fetch data By default tries to deduct class from tablet name.
Constructor Details
Instance Attribute Details
#name ⇒ Object (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 (controller) call(:authorize, controller) { true } end |
#columns ⇒ Object
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
62 63 64 |
# File 'lib/tablets/tablet.rb', line 62 def has?(name) @config.has?(name) end |
#options ⇒ Object
Returns general jquery-datatable configuration overrides By default returns empty options
16 17 18 |
# File 'lib/tablets/tablet.rb', line 16 def call(:options) { {} } end |
#payload ⇒ Object
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 |