Class: Decidim::Proposals::DiffRenderer

Inherits:
Object
  • Object
show all
Defined in:
app/services/decidim/proposals/diff_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ DiffRenderer

Returns a new instance of DiffRenderer.



6
7
8
# File 'app/services/decidim/proposals/diff_renderer.rb', line 6

def initialize(version)
  @version = version
end

Instance Method Details

#diffObject

Renders the diff of the given changeset. Doesn’t take into account translatable fields.

Returns a Hash, where keys are the fields that have changed and values are an array, the first element being the previous value and the last being the new one.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/decidim/proposals/diff_renderer.rb', line 14

def diff
  version.changeset.inject({}) do |diff, (attribute, values)|
    attribute = attribute.to_sym
    type = attribute_types[attribute]

    if type.blank?
      diff
    else
      parse_changeset(attribute, values, type, diff)
    end
  end
end