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
68 |
# File 'lib/tabulatr/renderer/column.rb', line 68 def action?() false end |
#association? ⇒ Boolean
66 |
# File 'lib/tabulatr/renderer/column.rb', line 66 def association?() false end |
#checkbox? ⇒ Boolean
67 |
# File 'lib/tabulatr/renderer/column.rb', line 67 def checkbox?() false end |
#coltype ⇒ Object
63 |
# File 'lib/tabulatr/renderer/column.rb', line 63 def coltype() 'column' end |
#column? ⇒ Boolean
65 |
# File 'lib/tabulatr/renderer/column.rb', line 65 def column?() true end |
#determine_appropriate_filter! ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/tabulatr/renderer/column.rb', line 97 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
62 |
# File 'lib/tabulatr/renderer/column.rb', line 62 def full_name() [table_name, name].compact.join(":") end |
#human_name ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tabulatr/renderer/column.rb', line 50 def human_name() h = .header if h && h.respond_to?(:call) h.() elsif h h else klass.human_attribute_name(name) end end |
#klassname ⇒ Object
48 |
# File 'lib/tabulatr/renderer/column.rb', line 48 def klassname() @_klassname ||= @klass.name.underscore end |
#principal_value(record, view) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tabulatr/renderer/column.rb', line 85 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
61 |
# File 'lib/tabulatr/renderer/column.rb', line 61 def sort_param() "#{klassname}_sort" end |
#value_for(record, view) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tabulatr/renderer/column.rb', line 70 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 |