Class: Katello::Validators::ContentViewPuppetModuleValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/lib/katello/validators/content_view_puppet_module_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/lib/katello/validators/content_view_puppet_module_validator.rb', line 4

def validate(record)
  if record.uuid.blank? && (record.name.blank? || record.author.blank?)
    invalid_parameters = _("Invalid puppet module parameters specified.  Either 'uuid' or 'name' and 'author' must be specified.")
    record.errors[:base] << invalid_parameters
    return
  end

  if record.name && record.author
    # validate that a puppet module exists with this name+author
    unless PuppetModule
            .in_repositories(record.content_view.puppet_repos)
            .where(:name => record.name, :author => record.author).present?

      invalid_parameters = _("Puppet Module with name='%{name}' and author='%{author}' does not exist") %
          { :name => record.name, :author => record.author }

      record.errors[:base] << invalid_parameters
    end
  end
end