Class: PaperTrail::Human::Core::ItemNameLoader
- Inherits:
-
Object
- Object
- PaperTrail::Human::Core::ItemNameLoader
- Defined in:
- lib/paper_trail/human/core/item_name_loader.rb
Instance Method Summary collapse
-
#initialize(configuration) ⇒ ItemNameLoader
constructor
A new instance of ItemNameLoader.
- #preload(versions) ⇒ Object
- #resolve(version, cache) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ ItemNameLoader
Returns a new instance of ItemNameLoader.
7 8 9 |
# File 'lib/paper_trail/human/core/item_name_loader.rb', line 7 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#preload(versions) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/paper_trail/human/core/item_name_loader.rb', line 11 def preload(versions) grouped = group_batchable(versions) grouped.each_with_object({}) do |(item_type, ids), cache| load_names(item_type, ids, cache) end end |
#resolve(version, cache) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/paper_trail/human/core/item_name_loader.rb', line 19 def resolve(version, cache) model_config = @configuration.config_for(version.item_type) return nil unless model_config&.item_name_attribute attr = model_config.item_name_attribute return attr.call(version) if attr.respond_to?(:call) cache[[version.item_type, version.item_id]] end |