Class: RSAML::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/rsaml/attribute.rb

Overview

Identifies an attribute by name and optionally includes its value(s).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *values) ⇒ Attribute

Initialize the attribute with the given name. Optionally pass an array of values.



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

def initialize(name, *values)
  @name = name
  @values = values      
end

Instance Attribute Details

#friendly_nameObject

A string that provides a more human-readable form of the attribute’s name, which may be useful in cases in which the actual Name is complex or opaque, such as an OID or a UUID.



13
14
15
# File 'lib/rsaml/attribute.rb', line 13

def friendly_name
  @friendly_name
end

#nameObject

The name of the attribute.



5
6
7
# File 'lib/rsaml/attribute.rb', line 5

def name
  @name
end

#name_formatObject

A URI reference representing the classification of the attribute name for purposes of interpreting the name



9
10
11
# File 'lib/rsaml/attribute.rb', line 9

def name_format
  @name_format
end

Class Method Details

.from_xml(element) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/rsaml/attribute.rb', line 50

def self.from_xml(element)
  element = REXML::Document.new(element).root if element.is_a?(String)
  attribute = Attribute.new(element.attribute('Name').value)
  if element.attribute('NameFormat')
    attribute.name_format = element.attribute('NameFormat').value
  end
  attribute
end

Instance Method Details

#extra_xml_attributesObject

extension point to allow arbitrary XML attributes to be added to <Attribute> constructs without the need for an explicit schema extension. This allows additional fields to be added as needed to supply additional parameters to be used, for example, in an attribute query. This attribute is a Hash of name/value pairs that is output directly with the <Attribute> XML element.



36
37
38
# File 'lib/rsaml/attribute.rb', line 36

def extra_xml_attributes
  @extra_xml_attributes ||= {}
end

#to_xml(xml = Builder::XmlMarkup.new) ⇒ Object

Construct an XML fragment representing the attribute



41
42
43
44
45
46
47
48
# File 'lib/rsaml/attribute.rb', line 41

def to_xml(xml=Builder::XmlMarkup.new)
  xml_attributes = {'Name' => name}
  xml_attributes['NameFormat'] = name_format unless name_format.nil?
  xml_attributes['FriendlyName'] = friendly_name unless friendly_name.nil?
  xml.tag!('saml:Attribute', xml_attributes.merge(extra_xml_attributes)) {
    values.each { |value| xml.tag!('saml:AttributeValue', value.to_s) }
  }
end

#validateObject

Validate the structure of the attribute.

Raises:



27
28
29
# File 'lib/rsaml/attribute.rb', line 27

def validate
  raise ValidationError, "Name is required" unless name
end

#valuesObject

An array of values for the attribute.



22
23
24
# File 'lib/rsaml/attribute.rb', line 22

def values
  @values ||= []
end