Class: SAML2::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/saml2/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



12
13
14
# File 'lib/saml2/base.rb', line 12

def xml
  @xml
end

Class Method Details

.from_xml(node) ⇒ Object



5
6
7
8
9
10
# File 'lib/saml2/base.rb', line 5

def self.from_xml(node)
  return nil unless node
  result = new
  result.from_xml(node)
  result
end

.load_object_array(node, element, klass) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/saml2/base.rb', line 38

def self.load_object_array(node, element, klass)
  node.xpath(element, Namespaces::ALL).map do |element_node|
    if klass.is_a?(Hash)
      klass[element_node.name].from_xml(element_node)
    else
      klass.from_xml(element_node)
    end
  end
end

.load_string_array(node, element) ⇒ Object



32
33
34
35
36
# File 'lib/saml2/base.rb', line 32

def self.load_string_array(node, element)
  node.xpath(element, Namespaces::ALL).map do |element_node|
    element_node.content&.strip
  end
end

.lookup_qname(qname, namespaces) ⇒ Object



48
49
50
51
# File 'lib/saml2/base.rb', line 48

def self.lookup_qname(qname, namespaces)
  prefix, local_name = split_qname(qname)
  [lookup_namespace(prefix, namespaces), local_name]
end

Instance Method Details

#from_xml(node) ⇒ Object



14
15
16
# File 'lib/saml2/base.rb', line 14

def from_xml(node)
  @xml = node
end

#to_sObject



18
19
20
21
# File 'lib/saml2/base.rb', line 18

def to_s
  # make sure to not FORMAT it - it breaks signatures!
  to_xml.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
end

#to_xmlObject



23
24
25
26
27
28
29
30
# File 'lib/saml2/base.rb', line 23

def to_xml
  unless instance_variable_defined?(:@document)
    builder = Nokogiri::XML::Builder.new
    build(builder)
    @document = builder.doc
  end
  @document
end