Class: SAML2::IndexedObject::Array

Inherits:
Array
  • Object
show all
Defined in:
lib/saml2/indexed_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects) ⇒ Array

Returns a new instance of Array.



35
36
37
38
39
40
41
42
# File 'lib/saml2/indexed_object.rb', line 35

def initialize(objects)
  replace(objects.sort_by { |object| object.index || 0 })
  @index = {}
  each { |object| @index[object.index] = object }
  @default = find { |object| object.default? } || first

  freeze
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



29
30
31
# File 'lib/saml2/indexed_object.rb', line 29

def default
  @default
end

Class Method Details

.from_xml(nodes) ⇒ Object



31
32
33
# File 'lib/saml2/indexed_object.rb', line 31

def self.from_xml(nodes)
  new(nodes.map { |node| name.split('::')[1..-2].inject(SAML2) { |mod, klass| mod.const_get(klass) }.from_xml(node) })
end

Instance Method Details

#[](index) ⇒ Object



44
45
46
# File 'lib/saml2/indexed_object.rb', line 44

def [](index)
  @index[index]
end

#resolve(index) ⇒ Object



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

def resolve(index)
  index ? self[index] : default
end