Class: Decidim::BaseDiffRenderer
- Inherits:
-
Object
- Object
- Decidim::BaseDiffRenderer
- Includes:
- TranslatableAttributes
- Defined in:
- app/services/decidim/base_diff_renderer.rb
Overview
This class holds common logic for diffing resources. It is supposed to be a base class for all other diff renderers, as it defines some helpful methods that later diff renderers can use.
Instance Method Summary collapse
-
#diff ⇒ Object
Renders the diff of the given changeset.
-
#initialize(version) ⇒ BaseDiffRenderer
constructor
A new instance of BaseDiffRenderer.
Methods included from TranslatableAttributes
Constructor Details
#initialize(version) ⇒ BaseDiffRenderer
Returns a new instance of BaseDiffRenderer.
10 11 12 |
# File 'app/services/decidim/base_diff_renderer.rb', line 10 def initialize(version) @version = version end |
Instance Method Details
#diff ⇒ Object
Renders the diff of the given changeset. Takes 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.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/decidim/base_diff_renderer.rb', line 18 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 |