Sha256: 117e0d0c7339f030da8791d7ff4d5bda3a8cf1c17fa1f3f6bc76582215105c3f
Contents?: true
Size: 1.7 KB
Versions: 36
Compression:
Stored size: 1.7 KB
Contents
module OM::XML::Validation # Class Methods -- These methods will be available on classes that include this Module module ClassMethods attr_accessor :schema_url attr_writer :schema_file ## # Validation Support ## # Validate the given document against the Schema provided by the root_property for this class def validate(doc) schema.validate(doc).each do |error| puts error.message end end # Retrieve the Nokogiri Schema for this class def schema @schema ||= Nokogiri::XML::Schema(schema_file.read) end # 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 def schema_file @schema_file ||= file_from_url(schema_url) end # Retrieve file from a url (used by schema_file method to retrieve schema file from the schema url) 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 private :file_from_url end # Instance Methods -- These methods will be available on instances of classes that include this module def self.included(klass) klass.extend(ClassMethods) end def validate self.class.validate(self) end end
Version data entries
36 entries across 36 versions & 2 rubygems