Class: Decidim::DecidimAwesome::VotingManifest
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::VotingManifest
- Includes:
- ActiveModel::Model, AttributeObject::Model
- Defined in:
- lib/decidim/decidim_awesome/voting_manifest.rb
Instance Method Summary collapse
-
#label_for(weight, context = {}) ⇒ Object
returns the label used in export or other places for a given weight defaults to a I18n key scoped under decidim_awesome.
-
#label_generator(&block) ⇒ Object
registers an optional label generator block.
-
#valid_weight?(weight, context = {}) ⇒ Boolean
validates the weight using the Proc defined by weight_validator Receives the weight and a context with the user and the proposal to be voted.
-
#weight_validator(&block) ⇒ Object
registers a weight validator.
Instance Method Details
#label_for(weight, context = {}) ⇒ Object
returns the label used in export or other places for a given weight defaults to a I18n key scoped under decidim_awesome
48 49 50 51 52 |
# File 'lib/decidim/decidim_awesome/voting_manifest.rb', line 48 def label_for(weight, context = {}) return I18n.t("decidim.decidim_awesome.voting.#{name}.weights.weight_#{weight}", default: "weight_#{weight}") unless @on_label_generation @on_label_generation.call(weight, **context) end |
#label_generator(&block) ⇒ Object
registers an optional label generator block
42 43 44 |
# File 'lib/decidim/decidim_awesome/voting_manifest.rb', line 42 def label_generator(&block) @on_label_generation = block end |
#valid_weight?(weight, context = {}) ⇒ Boolean
validates the weight using the Proc defined by weight_validator Receives the weight and a context with the user and the proposal to be voted
35 36 37 38 39 |
# File 'lib/decidim/decidim_awesome/voting_manifest.rb', line 35 def valid_weight?(weight, context = {}) return true unless @on_weight_validation @on_weight_validation.call(weight, **context) end |
#weight_validator(&block) ⇒ Object
registers a weight validator
29 30 31 |
# File 'lib/decidim/decidim_awesome/voting_manifest.rb', line 29 def weight_validator(&block) @on_weight_validation = block end |