Class: RivetCms::ContentValidator

Inherits:
Object
  • Object
show all
Defined in:
app/services/rivet_cms/content_validator.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(revision) ⇒ ContentValidator

Returns a new instance of ContentValidator.



7
8
9
10
# File 'app/services/rivet_cms/content_validator.rb', line 7

def initialize(revision)
  @revision = revision
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'app/services/rivet_cms/content_validator.rb', line 5

def errors
  @errors
end

Instance Method Details

#messagesObject



24
25
26
# File 'app/services/rivet_cms/content_validator.rb', line 24

def messages
  @errors.map { |e| "#{e.field_key} #{e.message}" }
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/services/rivet_cms/content_validator.rb', line 12

def valid?
  @errors.empty?
end

#validateObject

Raises:



16
17
18
19
20
21
22
# File 'app/services/rivet_cms/content_validator.rb', line 16

def validate
  raise TrashedEntryError, "entry is in the trash; restore it before validating" if @revision.document.nil?
  raise RemovedContentTypeError, "content type was removed; restore it before validating" if content_type.nil?

  validate_owner(@revision, content_type.fields.kept)
  self
end