class ActiveSet::ColumnInstruction
Public Class Methods
new(instructions_hash, item)
click to toggle source
# File lib/active_set/column_instruction.rb, line 7 def initialize(instructions_hash, item) @instructions_hash = instructions_hash.symbolize_keys @item = item end
Public Instance Methods
key()
click to toggle source
# File lib/active_set/column_instruction.rb, line 12 def key return @instructions_hash[:key] if @instructions_hash.key? :key return titleized_attribute_key unless attribute_instruction.attribute attribute_resource = attribute_instruction.resource_for(item: @item) return titleized_attribute_key unless attribute_resource&.class&.respond_to?(:human_attribute_name) attribute_resource.class.human_attribute_name(attribute_instruction.attribute) end
value()
click to toggle source
# File lib/active_set/column_instruction.rb, line 23 def value return default unless @instructions_hash.key?(:value) return @instructions_hash[:value].call(@item) if @instructions_hash[:value]&.respond_to? :call attribute_instruction.value_for(item: @item) end
Private Instance Methods
attribute_instruction()
click to toggle source
# File lib/active_set/column_instruction.rb, line 32 def attribute_instruction AttributeInstruction.new(@instructions_hash[:value], nil) end
default()
click to toggle source
# File lib/active_set/column_instruction.rb, line 36 def default return @instructions_hash[:default] if @instructions_hash.key? :default '—' end
titleized_attribute_key()
click to toggle source
# File lib/active_set/column_instruction.rb, line 42 def titleized_attribute_key attribute_instruction.keypath.map(&:titleize).join(' ') end