Class: TableHelpers::ReflectionHelper
- Inherits:
-
Object
- Object
- TableHelpers::ReflectionHelper
- Defined in:
- app/utils/table_helpers.rb
Instance Method Summary collapse
- #format_value(item, format) ⇒ Object
-
#initialize(method, template) ⇒ ReflectionHelper
constructor
A new instance of ReflectionHelper.
Constructor Details
#initialize(method, template) ⇒ ReflectionHelper
Returns a new instance of ReflectionHelper.
126 127 128 129 |
# File 'app/utils/table_helpers.rb', line 126 def initialize(method, template) @method = method @template = template end |
Instance Method Details
#format_value(item, format) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/utils/table_helpers.rb', line 131 def format_value(item, format) target = item.send(@method) case format when Proc format.call(target) when Hash, nil if target = {label_attr: :id, type: :link, target: :_blank}.merge(format || {}) v = target.send([:label_attr]) case [:type] when :link @template.link_to(v, target, target: [:target]) else v.to_s end else '' end else target.to_s end end |