Class: Column
- Inherits:
-
Object
- Object
- Column
- Defined in:
- app/tables/column.rb
Instance Attribute Summary collapse
-
#blank_value ⇒ Object
Returns the value of attribute blank_value.
-
#column_source ⇒ Object
Returns the value of attribute column_source.
-
#method ⇒ Object
Returns the value of attribute method.
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
-
#render_with ⇒ Object
Returns the value of attribute render_with.
-
#searchable ⇒ Object
Returns the value of attribute searchable.
-
#sortable ⇒ Object
Returns the value of attribute sortable.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
-
#virtual ⇒ Object
Returns the value of attribute virtual.
Instance Method Summary collapse
-
#initialize(table_name, model, name, *args) ⇒ Column
constructor
A new instance of Column.
Constructor Details
#initialize(table_name, model, name, *args) ⇒ Column
Returns a new instance of Column.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/tables/column.rb', line 5 def initialize(table_name, model, name, *args) self.table_name = table_name self.model = model self.name = name attributes = args.pop || {} self.method = attributes.fetch(:method, name).to_s self.column_source = attributes.fetch(:column_source, '').to_s virtual = (self.column_source.blank? and not self.model.column_names.include? self.method) self.virtual = attributes.fetch(:virtual, virtual) self.sortable = attributes.fetch(:sortable, !self.virtual) self.searchable = attributes.fetch(:searchable, !self.virtual) if virtual and not attributes.has_key?(:render_with) raise Exception, "Virtual columns are required to supply a render method (render_with: lambda): "\ "Column: #{self.name}, Datatable: #{self.table_name}, Model: #{self.model.name}" end self.render_with = attributes.fetch(:render_with, :default_render) self.blank_value = attributes.fetch(:blank_value, '–') define_singleton_method :render do |view, object| if self.render_with.kind_of? Symbol content = self.send(self.render_with, view, follow_source(object)) else content = self.render_with.call(view, object) end content.present? ? content.to_s.html_safe : self.blank_value end end |
Instance Attribute Details
#blank_value ⇒ Object
Returns the value of attribute blank_value.
3 4 5 |
# File 'app/tables/column.rb', line 3 def blank_value @blank_value end |
#column_source ⇒ Object
Returns the value of attribute column_source.
3 4 5 |
# File 'app/tables/column.rb', line 3 def column_source @column_source end |
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'app/tables/column.rb', line 3 def method @method end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'app/tables/column.rb', line 3 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'app/tables/column.rb', line 3 def name @name end |
#render_with ⇒ Object
Returns the value of attribute render_with.
3 4 5 |
# File 'app/tables/column.rb', line 3 def render_with @render_with end |
#searchable ⇒ Object
Returns the value of attribute searchable.
3 4 5 |
# File 'app/tables/column.rb', line 3 def searchable @searchable end |
#sortable ⇒ Object
Returns the value of attribute sortable.
3 4 5 |
# File 'app/tables/column.rb', line 3 def sortable @sortable end |
#table_name ⇒ Object
Returns the value of attribute table_name.
3 4 5 |
# File 'app/tables/column.rb', line 3 def table_name @table_name end |
#virtual ⇒ Object
Returns the value of attribute virtual.
3 4 5 |
# File 'app/tables/column.rb', line 3 def virtual @virtual end |