Class: SamlTool::Validator
- Inherits:
-
Object
- Object
- SamlTool::Validator
- Defined in:
- lib/saml_tool/validator.rb
Instance Attribute Summary collapse
-
#saml ⇒ Object
readonly
Returns the value of attribute saml.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(saml) ⇒ Validator
constructor
A new instance of Validator.
- #saml_document ⇒ Object
- #schema_path ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(saml) ⇒ Validator
5 6 7 |
# File 'lib/saml_tool/validator.rb', line 5 def initialize(saml) @saml = saml end |
Instance Attribute Details
#saml ⇒ Object (readonly)
Returns the value of attribute saml.
4 5 6 |
# File 'lib/saml_tool/validator.rb', line 4 def saml @saml end |
Instance Method Details
#errors ⇒ Object
14 15 16 |
# File 'lib/saml_tool/validator.rb', line 14 def errors @errors ||= [] end |
#saml_document ⇒ Object
35 36 37 |
# File 'lib/saml_tool/validator.rb', line 35 def saml_document @saml_document ||= Nokogiri::XML(saml) end |
#schema_path ⇒ Object
31 32 33 |
# File 'lib/saml_tool/validator.rb', line 31 def schema_path File.('../schema/', File.dirname(__FILE__)) end |
#valid? ⇒ Boolean
9 10 11 12 |
# File 'lib/saml_tool/validator.rb', line 9 def valid? validate errors.empty? end |
#validate ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/saml_tool/validator.rb', line 19 def validate # Need to load schema with other schemas in path # see http://ktulu.com.ar/blog/2011/06/26/resolving-validation-errors-using-nokogiri-and-schemas/ Dir.chdir(schema_path) do schema = Nokogiri::XML::Schema(File.read('localised-saml-schema-protocol-2.0.xsd')) schema.validate(saml_document).each do |error| errors << error. unless errors.include? error. end end end |