Class: OneLogin::RubySaml::Attributes
- Inherits:
-
Object
- Object
- OneLogin::RubySaml::Attributes
- Includes:
- Enumerable
- Defined in:
- lib/onelogin/ruby-saml/attributes.rb
Overview
SAML2 Attributes. Parse the Attributes from the AttributeStatement of the SAML Response.
Constant Summary collapse
- @@single_value_compatibility =
By default Attributes#[] is backwards compatible and returns only the first value for the attribute Setting this to
falsereturns all values for an attribute true
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.single_value_compatibility ⇒ Boolean
Get current status of backwards compatibility mode.
-
.single_value_compatibility=(value) ⇒ Object
Sets the backwards compatibility mode on/off.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Make comparable to another Attributes collection based on attributes.
-
#[](name) ⇒ String|Array
Retrieve attribute value(s).
- #add(name, values = []) ⇒ Object
-
#all ⇒ Array
Return all attributes as an array.
-
#each ⇒ Object
Iterate over all attributes.
-
#include?(name) ⇒ Boolean
Test attribute presence by name.
-
#initialize(attrs = {}) ⇒ Attributes
constructor
A new instance of Attributes.
-
#multi(name) ⇒ Array
Return all values for an attribute.
- #respond_to?(name) ⇒ Boolean
- #set(name, values) ⇒ Object (also: #[]=)
-
#single(name) ⇒ String
Return first value for an attribute.
Constructor Details
#initialize(attrs = {}) ⇒ Attributes
Returns a new instance of Attributes.
35 36 37 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 35 def initialize(attrs = {}) @attributes = attrs end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
138 139 140 141 142 143 144 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 138 def method_missing(name, *args, &block) if attributes.respond_to?(name) attributes.send(name, *args, &block) else super end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 9 def attributes @attributes end |
Class Method Details
.single_value_compatibility ⇒ Boolean
Returns Get current status of backwards compatibility mode.
18 19 20 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 18 def self.single_value_compatibility @@single_value_compatibility end |
.single_value_compatibility=(value) ⇒ Object
Sets the backwards compatibility mode on/off.
25 26 27 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 25 def self.single_value_compatibility=(value) @@single_value_compatibility = value end |
Instance Method Details
#==(other) ⇒ Boolean
Make comparable to another Attributes collection based on attributes
116 117 118 119 120 121 122 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 116 def ==(other) if other.is_a?(Attributes) all == other.all else super end end |
#[](name) ⇒ String|Array
Retrieve attribute value(s)
86 87 88 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 86 def [](name) self.class.single_value_compatibility ? single(name) : multi(name) end |
#add(name, values = []) ⇒ Object
107 108 109 110 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 107 def add(name, values = []) attributes[canonize_name(name)] ||= [] attributes[canonize_name(name)] += Array(values) end |
#all ⇒ Array
Return all attributes as an array
92 93 94 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 92 def all attributes end |
#each ⇒ Object
Iterate over all attributes
42 43 44 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 42 def each attributes.each{|name, values| yield name, values} end |
#include?(name) ⇒ Boolean
Test attribute presence by name
50 51 52 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 50 def include?(name) attributes.has_key?(canonize_name(name)) || attributes.has_key?(name) end |
#multi(name) ⇒ Array
Return all values for an attribute
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 66 def multi(name) values = attributes[canonize_name(name)] || attributes[name] if values.is_a?(Array) values elsif !values.nil? Array(values) else nil end end |
#respond_to?(name) ⇒ Boolean
124 125 126 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 124 def respond_to?(name) attributes.respond_to?(name) || super end |
#set(name, values) ⇒ Object Also known as: []=
99 100 101 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 99 def set(name, values) attributes[canonize_name(name)] = values end |
#single(name) ⇒ String
Return first value for an attribute
58 59 60 |
# File 'lib/onelogin/ruby-saml/attributes.rb', line 58 def single(name) multi(name).first if include?(name) end |