Class: SAML2::Attribute

Inherits:
Base
  • Object
show all
Defined in:
lib/saml2/attribute.rb,
lib/saml2/attribute/x500.rb

Direct Known Subclasses

X500, RequestedAttribute

Defined Under Namespace

Modules: NameFormats Classes: X500

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

load_object_array, load_string_array, lookup_qname, #to_s, #to_xml

Constructor Details

#initialize(name = nil, value = nil, friendly_name = nil, name_format = nil) ⇒ Attribute

Returns a new instance of Attribute.



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

def initialize(name = nil, value = nil, friendly_name = nil, name_format = nil)
  @name, @value, @friendly_name, @name_format = name, value, friendly_name, name_format
end

Instance Attribute Details

#friendly_nameObject

Returns the value of attribute friendly_name.



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

def friendly_name
  @friendly_name
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#name_formatObject

Returns the value of attribute name_format.



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

def name_format
  @name_format
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.create(name, value = nil) ⇒ Object



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

def create(name, value = nil)

  (class_for(name) || self).new(name, value)
end

.from_xml(node) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/saml2/attribute.rb', line 25

def from_xml(node)
  # pass through for subclasses
  return super unless self == Attribute

  # look for an appropriate subclass
  klass = class_for(node)
  klass ? klass.from_xml(node) : super
end

.inherited(klass) ⇒ Object



21
22
23
# File 'lib/saml2/attribute.rb', line 21

def inherited(klass)
  subclasses << klass
end

.subclassesObject



17
18
19
# File 'lib/saml2/attribute.rb', line 17

def subclasses
  @subclasses ||= []
end

Instance Method Details

#build(builder) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/saml2/attribute.rb', line 54

def build(builder)
  builder['saml'].Attribute('Name' => name) do |builder|
    builder.parent['FriendlyName'] = friendly_name if friendly_name
    builder.parent['NameFormat'] = name_format if name_format
    Array.wrap(value).each do |value|
      xsi_type, val = convert_to_xsi(value)
      builder['saml'].AttributeValue(val) do |builder|
        builder.parent['xsi:type'] = xsi_type if xsi_type
      end
    end
  end
end

#from_xml(node) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/saml2/attribute.rb', line 67

def from_xml(node)
  @name = node['Name']
  @friendly_name = node['FriendlyName']
  @name_format = node['NameFormat']
  values = node.xpath('saml:AttributeValue', Namespaces::ALL).map do |node|
    convert_from_xsi(node.attribute_with_ns('type', Namespaces::XSI), node.content && node.content.strip)
  end
  @value = case values.length
           when 0; nil
           when 1; values.first
           else; values
           end
end