Class: ActiveElement::Components::Util::DefaultDisplayValue
- Inherits:
-
Object
- Object
- ActiveElement::Components::Util::DefaultDisplayValue
- Defined in:
- lib/active_element/components/util/default_display_value.rb
Overview
Infers a default display value from any given object using multiple strategies.
Constant Summary collapse
- DEFAULT_FIELDS =
%i[display_name email name username].freeze
Instance Method Summary collapse
-
#initialize(object:) ⇒ DefaultDisplayValue
constructor
A new instance of DefaultDisplayValue.
- #value ⇒ Object
Constructor Details
#initialize(object:) ⇒ DefaultDisplayValue
Returns a new instance of DefaultDisplayValue.
10 11 12 |
# File 'lib/active_element/components/util/default_display_value.rb', line 10 def initialize(object:) @object = object end |
Instance Method Details
#value ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/active_element/components/util/default_display_value.rb', line 14 def value if object.respond_to?(:default_display_attribute) return object.public_send(object.default_display_attribute) end DEFAULT_FIELDS.each do |field| return object.public_send(field) if active_record_value?(field) return object[field] if hash_key(field) if hash_value?(field) end end |