Class: ActiveSet::ColumnInstruction
- Inherits:
-
Object
- Object
- ActiveSet::ColumnInstruction
- Defined in:
- lib/active_set/column_instruction.rb
Instance Method Summary collapse
-
#initialize(instructions_hash, item) ⇒ ColumnInstruction
constructor
A new instance of ColumnInstruction.
- #key ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(instructions_hash, item) ⇒ ColumnInstruction
Returns a new instance of ColumnInstruction.
7 8 9 10 |
# File 'lib/active_set/column_instruction.rb', line 7 def initialize(instructions_hash, item) @instructions_hash = instructions_hash.symbolize_keys @item = item end |
Instance Method Details
#key ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# 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 ⇒ Object
23 24 25 26 27 28 |
# 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 |