Module: OM::XML::Validation::ClassMethods

Defined in:
lib/om/xml/validation.rb

Overview

Class Methods – These methods will be available on classes that include this Module

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schema_fileObject

Retrieve the schema file for this class If the schema file is not already set, it will be loaded from the schema url provided in the root_property configuration for the class



28
29
30
# File 'lib/om/xml/validation.rb', line 28

def schema_file
  @schema_file ||= file_from_url(schema_url)
end

#schema_urlObject

Returns the value of attribute schema_url



7
8
9
# File 'lib/om/xml/validation.rb', line 7

def schema_url
  @schema_url
end

Instance Method Details

#schemaObject

Retrieve the Nokogiri Schema for this class



22
23
24
# File 'lib/om/xml/validation.rb', line 22

def schema
  @schema ||= Nokogiri::XML::Schema(schema_file.read)
end

#validate(doc) ⇒ Object

Validate the given document against the Schema provided by the root_property for this class



15
16
17
18
19
# File 'lib/om/xml/validation.rb', line 15

def validate(doc)
  schema.validate(doc).each do |error|
      puts error.message
  end
end