Class: Econfig::BackendCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/econfig/backend_collection.rb

Instance Method Summary collapse

Constructor Details

#initializeBackendCollection

Returns a new instance of BackendCollection.



5
6
7
# File 'lib/econfig/backend_collection.rb', line 5

def initialize
  @backends = []
end

Instance Method Details

#[](name) ⇒ Object



9
10
11
12
# File 'lib/econfig/backend_collection.rb', line 9

def [](name)
  pair = @backends.assoc(name)
  pair.last if pair
end

#delete(name) ⇒ Object



43
44
45
# File 'lib/econfig/backend_collection.rb', line 43

def delete(name)
  @backends.delete_at(index_of!(name))
end

#eachObject



14
15
16
17
18
19
20
# File 'lib/econfig/backend_collection.rb', line 14

def each
  if block_given?
    @backends.each { |(name, backend)| yield backend }
  else
    enum_for { @backends.length }
  end
end

#insert_after(other, name, backend) ⇒ Object



38
39
40
41
# File 'lib/econfig/backend_collection.rb', line 38

def insert_after(other, name, backend)
  exists‽(name)
  @backends.insert(index_of!(other) + 1, [name, backend])
end

#insert_before(other, name, backend) ⇒ Object



33
34
35
36
# File 'lib/econfig/backend_collection.rb', line 33

def insert_before(other, name, backend)
  exists‽(name)
  @backends.insert(index_of!(other), [name, backend])
end

#push(name, backend) ⇒ Object Also known as: use



22
23
24
25
# File 'lib/econfig/backend_collection.rb', line 22

def push(name, backend)
  exists‽(name)
  @backends.push([name, backend])
end

#unshift(name, backend) ⇒ Object



28
29
30
31
# File 'lib/econfig/backend_collection.rb', line 28

def unshift(name, backend)
  exists‽(name)
  @backends.unshift([name, backend])
end