Sha256: fc03cb7f19597911d1c7a9609c90895492073d7c324945b04290ddf35bee691e

Contents?: true

Size: 831 Bytes

Versions: 31

Compression:

Stored size: 831 Bytes

Contents

# frozen_string_literal: true

# A custom validator to make sure features are correctly assigned to a model.
#
# Adds a presence validation and checks that the manifest is the correct one.
class FeatureValidator < ActiveModel::EachValidator
  # Validates the arguiments passed to the validator.
  def check_validity!
    raise ArgumentError, "You must include a `manifest` option with the name of the manifest to validate when validating a feature" unless options[:manifest].present?
  end

  # The actual validator method. It is called when ActiveRecord iterates
  # over all the validators.
  def validate_each(record, attribute, feature)
    unless feature
      record.errors[attribute] << :blank
      return
    end

    record.errors[attribute] << :invalid if feature.manifest_name.to_s != options[:manifest].to_s
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
decidim-core-0.6.8 lib/decidim/feature_validator.rb
decidim-0.6.8 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.7 lib/decidim/feature_validator.rb
decidim-0.6.7 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.6 lib/decidim/feature_validator.rb
decidim-0.6.6 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.5 lib/decidim/feature_validator.rb
decidim-0.6.5 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.4 lib/decidim/feature_validator.rb
decidim-0.6.4 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.3 lib/decidim/feature_validator.rb
decidim-0.6.3 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.2 lib/decidim/feature_validator.rb
decidim-0.6.2 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.1 lib/decidim/feature_validator.rb
decidim-0.6.1 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.6.0 lib/decidim/feature_validator.rb
decidim-0.6.0 decidim-core/lib/decidim/feature_validator.rb
decidim-core-0.5.1 lib/decidim/feature_validator.rb
decidim-0.5.1 decidim-core/lib/decidim/feature_validator.rb