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

Constructor Details

#initializeBase

Returns a new instance of Base.



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

def initialize
  @pretty = true
end

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 = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/saml2/base.rb', line 59

def self.load_object_array(node, element, klass = nil)
  node.xpath(element, Namespaces::ALL).map do |element_node|
    if klass.nil?
      SAML2.const_get(element_node.name, false).from_xml(element_node)
    elsif 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



53
54
55
56
57
# File 'lib/saml2/base.rb', line 53

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



71
72
73
74
# File 'lib/saml2/base.rb', line 71

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

Instance Method Details

#build(builder) ⇒ Object



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

def build(builder)
end

#from_xml(node) ⇒ Object



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

def from_xml(node)
  @xml = node
end

#inspectObject



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

def inspect
  "#<#{self.class.name} #{instance_variables.map { |iv| next if iv == :@xml; "#{iv}=#{instance_variable_get(iv).inspect}" }.compact.join(", ") }>"
end

#to_s(pretty: nil) ⇒ Object



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

def to_s(pretty: nil)
  pretty = @pretty if pretty.nil?
  if xml
    xml.to_s
  elsif pretty
    to_xml.to_s
  else
    # make sure to not FORMAT it - it breaks signatures!
    to_xml.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
  end
end

#to_xmlObject



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

def to_xml
  unless instance_variable_defined?(:@document)
    builder = Nokogiri::XML::Builder.new
    build(builder)
    @document = builder.doc
    # if we're re-serializing a parsed document (i.e. after mutating/parsing it),
    # forget the original document we parsed
    @xml = nil
  end
  @document
end