Sha256: b704a0d3802fafe86637053e9cbbcd5b73dce00c011922d29227ad23025587e5

Contents?: true

Size: 837 Bytes

Versions: 63

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

# A custom validator to make sure components are correctly assigned to a model.
#
# Adds a presence validation and checks that the manifest is the correct one.
class ComponentValidator < 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 component" if options[:manifest].blank?
  end

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

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

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
decidim-core-0.26.10 lib/decidim/component_validator.rb
decidim-core-0.26.9 lib/decidim/component_validator.rb
decidim-core-0.26.8 lib/decidim/component_validator.rb
decidim-core-0.26.7 lib/decidim/component_validator.rb
decidim-core-0.26.5 lib/decidim/component_validator.rb
decidim-core-0.26.4 lib/decidim/component_validator.rb
decidim-core-0.26.3 lib/decidim/component_validator.rb
decidim-core-0.26.2 lib/decidim/component_validator.rb
decidim-core-0.26.1 lib/decidim/component_validator.rb
decidim-core-0.26.0 lib/decidim/component_validator.rb
decidim-core-0.26.0.rc2 lib/decidim/component_validator.rb
decidim-core-0.26.0.rc1 lib/decidim/component_validator.rb
decidim-core-0.25.2 lib/decidim/component_validator.rb
decidim-core-0.25.1 lib/decidim/component_validator.rb
decidim-core-0.25.0 lib/decidim/component_validator.rb
decidim-core-0.25.0.rc4 lib/decidim/component_validator.rb
decidim-core-0.25.0.rc3 lib/decidim/component_validator.rb
decidim-core-0.25.0.rc2 lib/decidim/component_validator.rb
decidim-core-0.25.0.rc1 lib/decidim/component_validator.rb
decidim-core-0.24.3 lib/decidim/component_validator.rb