Class: PaperTrail::RelatedChanges::BuildChanges

Inherits:
Object
  • Object
show all
Defined in:
lib/paper_trail/related_changes/build_changes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results, model_type_children, item_type, item_id) ⇒ BuildChanges

Returns a new instance of BuildChanges.



9
10
11
12
13
14
# File 'lib/paper_trail/related_changes/build_changes.rb', line 9

def initialize(results, model_type_children, item_type, item_id)
  @results             = results
  @model_type_children = model_type_children
  @item_type           = item_type
  @item_id             = item_id
end

Instance Attribute Details

#item_idObject (readonly)

Returns the value of attribute item_id.



4
5
6
# File 'lib/paper_trail/related_changes/build_changes.rb', line 4

def item_id
  @item_id
end

#item_typeObject (readonly)

Returns the value of attribute item_type.



4
5
6
# File 'lib/paper_trail/related_changes/build_changes.rb', line 4

def item_type
  @item_type
end

#model_type_childrenObject (readonly)

Returns the value of attribute model_type_children.



4
5
6
# File 'lib/paper_trail/related_changes/build_changes.rb', line 4

def model_type_children
  @model_type_children
end

#resultsObject (readonly)

Returns the value of attribute results.



4
5
6
# File 'lib/paper_trail/related_changes/build_changes.rb', line 4

def results
  @results
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/paper_trail/related_changes/build_changes.rb', line 16

def call
  changes = results.map do |root_version, versions, request_id|
    versions_serialized         = versions_serialized(versions)
    root_change                 = change_with_root(request_id, root_version, versions_serialized)
    root_change.change.children = children_versions(versions_serialized).map(&:change)
    root_change.change
  end.compact

  remove_duplicate_changes(changes)
end