Module: DataShifter::Internal::RecordUtils
- Defined in:
- lib/data_shifter/internal/record_utils.rb
Overview
Record-related utility functions. All methods are stateless module functions.
Class Method Summary collapse
-
.default_label(items) ⇒ String
Derive a default label from an array of items.
-
.default_label_for_relation(relation) ⇒ String
Derive a default label from an ActiveRecord::Relation.
-
.identifier(record) ⇒ String
Generate a human-readable identifier for a record.
Class Method Details
.default_label(items) ⇒ String
Derive a default label from an array of items.
24 25 26 27 |
# File 'lib/data_shifter/internal/record_utils.rb', line 24 def default_label(items) sample = items.first sample.respond_to?(:model_name) ? sample.model_name.human.pluralize : "records" end |
.default_label_for_relation(relation) ⇒ String
Derive a default label from an ActiveRecord::Relation.
33 34 35 |
# File 'lib/data_shifter/internal/record_utils.rb', line 33 def default_label_for_relation(relation) relation.respond_to?(:model) ? relation.model.model_name.human.pluralize : "records" end |
.identifier(record) ⇒ String
Generate a human-readable identifier for a record.
14 15 16 17 18 |
# File 'lib/data_shifter/internal/record_utils.rb', line 14 def identifier(record) return "#{record.class.name}##{record.id}" if record.respond_to?(:id) record.inspect.truncate(80) end |