Class: PaperTrail::Human::Core::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail/human/core/presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Presenter

Returns a new instance of Presenter.



7
8
9
10
# File 'lib/paper_trail/human/core/presenter.rb', line 7

def initialize(configuration)
  @configuration = configuration
  @change_extractor = ChangeExtractor.new
end

Instance Method Details

#call(version, only: nil, except: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/paper_trail/human/core/presenter.rb', line 12

def call(version, only: nil, except: nil)
  changes = @change_extractor.call(version)
  model_config = @configuration.config_for(version.item_type)
  formatter = FieldFormatter.new(
    model_config,
    version.item_type,
    field_name_resolver: @configuration.field_name_resolver
  )

  result = {
    user: @configuration.resolve_whodunnit(version.whodunnit),
    event: EventTranslator.call(version.event, translate: @configuration.translate_events),
    model: version.item_type,
    item_id: version.item_id,
    created_at: version.created_at,
    fields: build_fields(changes, formatter, version.event, only: only, except: except)
  }

  item_name = @configuration.resolve_item_name(version)
  result[:item_name] = item_name if item_name

  apply_after_format(result, version)
end