Class: Decidim::Proposals::DiffRenderer
- Inherits:
-
Object
- Object
- Decidim::Proposals::DiffRenderer
- Defined in:
- app/services/decidim/proposals/diff_renderer.rb
Instance Method Summary collapse
-
#diff ⇒ Object
Renders the diff of the given changeset.
-
#initialize(version) ⇒ DiffRenderer
constructor
A new instance of DiffRenderer.
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
#diff ⇒ Object
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 |