Class: DynatableBuilder::Table
- Inherits:
-
Object
- Object
- DynatableBuilder::Table
- Defined in:
- lib/dynatable_builder/table.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Class Method Summary collapse
- .base_scope ⇒ Object
- .columns(*cols, &block) ⇒ Object
- .helpers(*mod_or_mods, &block) ⇒ Object
- .includes(*args) ⇒ Object
- .joins(*args) ⇒ Object
- .scope(model_name = nil, &block) ⇒ Object
- .search(*cols, &block) ⇒ Object
Instance Method Summary collapse
- #as_json(opts = {}) ⇒ Object
-
#initialize(view) ⇒ Table
constructor
A new instance of Table.
- #to_json(opts = {}) ⇒ Object
Constructor Details
#initialize(view) ⇒ Table
Returns a new instance of Table.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dynatable_builder/table.rb', line 12 def initialize(view) @view = view @builder = Builder.new(@view, self.class.base_scope, { columns: defined_columns, includes: defined_includes, joins: defined_joins, search: defined_search, helpers: defined_helpers }) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
5 6 7 |
# File 'lib/dynatable_builder/table.rb', line 5 def builder @builder end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
5 6 7 |
# File 'lib/dynatable_builder/table.rb', line 5 def view @view end |
Class Method Details
.base_scope ⇒ Object
69 70 71 |
# File 'lib/dynatable_builder/table.rb', line 69 def base_scope defined_scope.presence || name.gsub(/Table/, '').singularize.constantize end |
.columns(*cols, &block) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/dynatable_builder/table.rb', line 36 def columns(*cols, &block) if block_given? self.defined_columns = block else (self.defined_columns ||= []) << cols self.defined_columns.flatten! end end |
.helpers(*mod_or_mods, &block) ⇒ Object
64 65 66 67 |
# File 'lib/dynatable_builder/table.rb', line 64 def helpers(*mod_or_mods, &block) (self.defined_helpers ||= []) << (block || mod_or_mods) self.defined_helpers.flatten! end |
.includes(*args) ⇒ Object
54 55 56 57 |
# File 'lib/dynatable_builder/table.rb', line 54 def includes(*args) (self.defined_includes ||= []) << args self.defined_includes.flatten! end |
.joins(*args) ⇒ Object
59 60 61 62 |
# File 'lib/dynatable_builder/table.rb', line 59 def joins(*args) (self.defined_joins ||= []) << args self.defined_joins.flatten! end |
.scope(model_name = nil, &block) ⇒ Object
32 33 34 |
# File 'lib/dynatable_builder/table.rb', line 32 def scope(model_name = nil, &block) self.defined_scope = block_given? ? block : model_name end |
.search(*cols, &block) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/dynatable_builder/table.rb', line 45 def search(*cols, &block) if block_given? self.defined_search = block else (self.defined_search ||= []) << cols self.defined_search.flatten! end end |
Instance Method Details
#as_json(opts = {}) ⇒ Object
27 28 29 |
# File 'lib/dynatable_builder/table.rb', line 27 def as_json(opts = {}) builder.as_json end |
#to_json(opts = {}) ⇒ Object
23 24 25 |
# File 'lib/dynatable_builder/table.rb', line 23 def to_json(opts = {}) builder.to_json end |