Module: ActiveElement::Components::Util::RecordMapping

Included in:
DisplayValueMapping, FormValueMapping
Defined in:
lib/active_element/components/util/record_mapping.rb

Overview

Maps ActiveRecord record columns and fields to values.

Constant Summary collapse

DATABASE_TYPES =
%i[
  string json jsonb integer decimal float datetime time date boolean binary geometry
].freeze

Instance Method Summary collapse

Instance Method Details

#initialize(component:, record:, field:, options: {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/active_element/components/util/record_mapping.rb', line 12

def initialize(component:, record:, field:, options: {})
  @component = component
  @record = record
  @field = field
  @options = options
end

#typeObject



26
27
28
# File 'lib/active_element/components/util/record_mapping.rb', line 26

def type
  column&.type
end

#valueObject



19
20
21
22
23
24
# File 'lib/active_element/components/util/record_mapping.rb', line 19

def value
  return value_from_config if value_from_config.present?
  return mapped_value_from_record if active_record? || column.present?

  value_from_record
end