Class: MightyGrid::Column
- Inherits:
-
Object
- Object
- MightyGrid::Column
- Defined in:
- lib/mighty_grid/column.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#render_value ⇒ Object
Returns the value of attribute render_value.
-
#th_attrs ⇒ Object
readonly
Returns the value of attribute th_attrs.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Column
constructor
A new instance of Column.
- #render(record) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mighty_grid/column.rb', line 6 def initialize( = {}, &block) @attrs = {} @th_attrs = {} @attribute = .delete(:attribute) if .key?(:attribute) @options ||= if block_given? @render_value = block else @render_value = @attribute end @model = @options[:model] fail MightyGrid::Exceptions::ArgumentError.new('Model of field for filtering should have type ActiveRecord') if @model && @model.superclass != ActiveRecord::Base @attrs = @options[:html] if @options.key?(:html) @th_attrs = @options[:th_html] if @options.key?(:th_html) @title = @options.key?(:title) && @options[:title] || '' end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def attribute @attribute end |
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def attrs @attrs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def @options end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def partial @partial end |
#render_value ⇒ Object
Returns the value of attribute render_value.
4 5 6 |
# File 'lib/mighty_grid/column.rb', line 4 def render_value @render_value end |
#th_attrs ⇒ Object (readonly)
Returns the value of attribute th_attrs.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def th_attrs @th_attrs end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/mighty_grid/column.rb', line 3 def title @title end |
Instance Method Details
#render(record) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mighty_grid/column.rb', line 28 def render(record) case @render_value when String, Symbol rec = @model ? record.send(@model.to_s.underscore) : record return rec[@render_value.to_sym] when Proc value, attrs = @render_value.call(record) @attrs.merge!(attrs || {}) return ERB::Util.h(value).to_s.html_safe else # raise end end |