Class: Tabulatr::Renderer::Column
- Inherits:
-
Object
- Object
- Tabulatr::Renderer::Column
- Includes:
- ActiveModel::Model
- Defined in:
- lib/tabulatr/renderer/column.rb
Overview
– Copyright © 2010-2014 Peter Horn & Florian Thomas, metaminded UG
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #action? ⇒ Boolean
- #association? ⇒ Boolean
- #checkbox? ⇒ Boolean
- #coltype ⇒ Object
- #column? ⇒ Boolean
- #determine_appropriate_filter! ⇒ Object
- #full_name ⇒ Object
- #human_name ⇒ Object
- #klassname ⇒ Object
- #principal_value(record, view) ⇒ Object
- #sort_param ⇒ Object
- #value_for(record, view) ⇒ Object
Class Method Details
.from(name: nil, table_name: nil, col_options: nil, klass: nil, output: nil, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tabulatr/renderer/column.rb', line 31 def self.from( name: nil, table_name: nil, col_options: nil, klass: nil, output: nil, &block) self.new( name: name, table_name: table_name, col_options: , klass: klass, output: output, block: block ) end |
Instance Method Details
#action? ⇒ Boolean
57 |
# File 'lib/tabulatr/renderer/column.rb', line 57 def action?() false end |
#association? ⇒ Boolean
55 |
# File 'lib/tabulatr/renderer/column.rb', line 55 def association?() false end |
#checkbox? ⇒ Boolean
56 |
# File 'lib/tabulatr/renderer/column.rb', line 56 def checkbox?() false end |
#coltype ⇒ Object
52 |
# File 'lib/tabulatr/renderer/column.rb', line 52 def coltype() 'column' end |
#column? ⇒ Boolean
54 |
# File 'lib/tabulatr/renderer/column.rb', line 54 def column?() true end |
#determine_appropriate_filter! ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/tabulatr/renderer/column.rb', line 86 def determine_appropriate_filter! typ = self.klass.columns_hash[self.name.to_s].type.to_sym rescue nil case typ when :integer then self..filter = filter_type_for_integer when :enum then self..filter = :enum when :float, :decimal then self..filter = :decimal when :string, :text then self..filter = :like when :date, :time, :datetime, :timestamp then self..filter = :date when :boolean then self..filter = :checkbox when nil then self..filter = :exact else raise "Unknown filter type for #{self.name}: »#{typ}«" end end |
#full_name ⇒ Object
51 |
# File 'lib/tabulatr/renderer/column.rb', line 51 def full_name() [table_name, name].compact.join(":") end |
#human_name ⇒ Object
49 |
# File 'lib/tabulatr/renderer/column.rb', line 49 def human_name() .header || klass.human_attribute_name(name) end |
#klassname ⇒ Object
48 |
# File 'lib/tabulatr/renderer/column.rb', line 48 def klassname() @_klassname ||= @klass.name.underscore end |
#principal_value(record, view) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tabulatr/renderer/column.rb', line 74 def principal_value(record, view) if output view.instance_exec(record, &output) elsif block view.instance_exec(record, &block) elsif name record.send name else nil end end |
#sort_param ⇒ Object
50 |
# File 'lib/tabulatr/renderer/column.rb', line 50 def sort_param() "#{klassname}_sort" end |
#value_for(record, view) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tabulatr/renderer/column.rb', line 59 def value_for(record, view) val = principal_value(record, view) if self..format.present? if val.respond_to?(:to_ary) val.map do |v| format_value(v, view) end else format_value(val, view) end else val end end |