module OM::XML::Validation::ClassMethods
Class Methods – These methods will be available on classes that include this Module
Attributes
schema_file[W]
schema_url[RW]
Public Instance Methods
schema()
click to toggle source
Retrieve the Nokogiri Schema for this class
# File lib/om/xml/validation.rb, line 22 def schema @schema ||= Nokogiri::XML::Schema(schema_file.read) end
schema_file()
click to toggle source
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
# File lib/om/xml/validation.rb, line 28 def schema_file @schema_file ||= file_from_url(schema_url) end
validate(doc)
click to toggle source
Validate the given document against the Schema provided by the root_property for this class
# File lib/om/xml/validation.rb, line 15 def validate(doc) schema.validate(doc).each do |error| puts error.message end end
Private Instance Methods
file_from_url( url )
click to toggle source
Retrieve file from a url (used by schema_file
method to retrieve schema file from the schema url)
# File lib/om/xml/validation.rb, line 33 def file_from_url( url ) # parsed_url = URI.parse( url ) # # if parsed_url.class != URI::HTTP # raise "Invalid URL. Could not parse #{url} as a HTTP url." # end begin file = open( url ) return file rescue OpenURI::HTTPError => e raise "Could not retrieve file from #{url}. Error: #{e}" rescue Exception => e raise "Could not retrieve file from #{url}. Error: #{e}" end end