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



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

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

#schema_urlObject

Returns the value of attribute schema_url.



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

def schema_url
  @schema_url
end

Instance Method Details

#schemaObject

Retrieve the Nokogiri Schema for this class



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

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



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

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