module Decidim::HasReference
A concern with the components needed when you want a model to have a reference.
Public Instance Methods
calculate_reference()
click to toggle source
Public: Calculates a unique reference for the model using the function provided by configuration. Works for both component resources and participatory spaces.
Returns a String.
# File lib/decidim/has_reference.rb, line 27 def calculate_reference Decidim.reference_generator.call(self, respond_to?(:component) ? component : nil) end
reference()
click to toggle source
# File lib/decidim/has_reference.rb, line 16 def reference self[:reference] || calculate_reference end
store_reference()
click to toggle source
Internal: Sets the unique reference to the model. Note that if the resource implements `Decidim::Traceable` then any normal update (or `update`) will create a new version through an ActiveRecord update callback, but here we can't track the author of the version, so we use the `update_column` method which does not trigger callbacks.
Returns nothing.
# File lib/decidim/has_reference.rb, line 38 def store_reference self[:reference] ||= calculate_reference return unless changed? # rubocop:disable Rails/SkipsModelValidations update_column(:reference, self[:reference]) # rubocop:enable Rails/SkipsModelValidations end