Class: RSAML::Attribute
- Inherits:
-
Object
- Object
- RSAML::Attribute
- Defined in:
- lib/rsaml/attribute.rb
Overview
Identifies an attribute by name and optionally includes its value(s).
Instance Attribute Summary collapse
-
#friendly_name ⇒ Object
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.
-
#name ⇒ Object
The name of the attribute.
-
#name_format ⇒ Object
A URI reference representing the classification of the attribute name for purposes of interpreting the name.
Class Method Summary collapse
Instance Method Summary collapse
-
#extra_xml_attributes ⇒ Object
extension point to allow arbitrary XML attributes to be added to
constructs without the need for an explicit schema extension. -
#initialize(name, *values) ⇒ Attribute
constructor
Initialize the attribute with the given name.
-
#to_xml(xml = Builder::XmlMarkup.new) ⇒ Object
Construct an XML fragment representing the attribute.
-
#validate ⇒ Object
Validate the structure of the attribute.
-
#values ⇒ Object
An array of values for the attribute.
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_name ⇒ Object
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 |
#name ⇒ Object
The name of the attribute.
5 6 7 |
# File 'lib/rsaml/attribute.rb', line 5 def name @name end |
#name_format ⇒ Object
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_attributes ⇒ Object
extension point to allow arbitrary XML attributes to be added to
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 |
#validate ⇒ Object
Validate the structure of the attribute.
27 28 29 |
# File 'lib/rsaml/attribute.rb', line 27 def validate raise ValidationError, "Name is required" unless name end |
#values ⇒ Object
An array of values for the attribute.
22 23 24 |
# File 'lib/rsaml/attribute.rb', line 22 def values @values ||= [] end |