module PBCore
PBCore
Error
classes and methods.
The classes and methods in this file intend to serve the following purposes:
1) Provide a base class for all PBCore errors, to that host applications can easily rescue from all errors thrown by this gem. 2) Provide specific error classes, with specific error messages, for specific situations. This helps developers of host applications to quickly solve bugs they may encounter when using the gem. 3) Provide module specific module methods that will: a) encapsulate conditional logic for specific situaitons b) raise specific errors
New error classes should be created as new error conditions for specific situations arise. The pattern to follow should be:
1) Create a new error class that extends PBCore::Error. 2) The error class should be named in a way that indicates the specific situation. 3) The constructor of the error class should use named arguments, and include all information necessary to provide a detailed error message to developers, ideally with some kind of instruction on how to correct the problem. 3) A module method should be created to encapsulate the logic need to determine if an error should be raised. 4) The module name should beging with "fail_if_" or "fail_unless_", followed by the snake-case name of the specific error class to be raised. 5) The module method should test the condition, and raise the specific error. This implies that the module method must also receive all information necessary to pass along to the constructor of the error class.
Constants
- GEM_ROOT
- VERSION
Public Class Methods
fail_if_base_is_not_pbcore_element(included_module:, base:)
click to toggle source
# File lib/pbcore/errors.rb, line 42 def self.fail_if_base_is_not_pbcore_element(included_module:, base:) raise BaseIsNotPBCoreElement.new(included_module: included_module, base: base) unless base.ancestors.include? PBCore::Element end
fail_if_missing_build_xml_block(element_class:)
click to toggle source
# File lib/pbcore/errors.rb, line 52 def self.fail_if_missing_build_xml_block(element_class:) raise ElementMissingBuildXMLBlock.new(element_class: element_class) unless element_class.build_block end
validate(xml)
click to toggle source
# File lib/pbcore.rb, line 39 def validate(xml) errors = Nokogiri::XML::Schema(xsd).validate(Nokogiri::XML(xml)) raise ValidationError, "#{errors.count} errors:\n#{errors.join("\n")}" unless errors.empty? end
xsd()
click to toggle source
# File lib/pbcore.rb, line 35 def xsd File.read(File.join(GEM_ROOT, 'lib', 'pbcore-2.1.xsd')) end