Class: BlueprintConfig::BackendCollection
- Inherits:
-
Object
- Object
- BlueprintConfig::BackendCollection
- Includes:
- Enumerable
- Defined in:
- lib/blueprint_config/backend_collection.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #delete(name) ⇒ Object
- #each ⇒ Object
- #fresh? ⇒ Boolean
-
#initialize ⇒ BackendCollection
constructor
A new instance of BackendCollection.
- #insert_after(other, name, backend) ⇒ Object
- #insert_before(other, name, backend) ⇒ Object
- #push(name, backend) ⇒ Object (also: #use)
- #unshift(name, backend) ⇒ Object
Constructor Details
#initialize ⇒ BackendCollection
Returns a new instance of BackendCollection.
7 8 9 |
# File 'lib/blueprint_config/backend_collection.rb', line 7 def initialize @backends = [] end |
Instance Method Details
#[](name) ⇒ Object
11 12 13 14 |
# File 'lib/blueprint_config/backend_collection.rb', line 11 def [](name) pair = @backends.assoc(name) pair&.last end |
#delete(name) ⇒ Object
45 46 47 |
# File 'lib/blueprint_config/backend_collection.rb', line 45 def delete(name) @backends.delete_at(index_of!(name)) end |
#each ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/blueprint_config/backend_collection.rb', line 16 def each if block_given? @backends.each { |(_name, backend)| yield backend } else enum_for { @backends.length } end end |
#fresh? ⇒ Boolean
49 50 51 |
# File 'lib/blueprint_config/backend_collection.rb', line 49 def fresh? @backends.all? { |(_name, backend)| backend.fresh? } end |
#insert_after(other, name, backend) ⇒ Object
40 41 42 43 |
# File 'lib/blueprint_config/backend_collection.rb', line 40 def insert_after(other, name, backend) exists?(name) @backends.insert(index_of!(other) + 1, [name, backend]) end |
#insert_before(other, name, backend) ⇒ Object
35 36 37 38 |
# File 'lib/blueprint_config/backend_collection.rb', line 35 def insert_before(other, name, backend) exists?(name) @backends.insert(index_of!(other), [name, backend]) end |
#push(name, backend) ⇒ Object Also known as: use
24 25 26 27 |
# File 'lib/blueprint_config/backend_collection.rb', line 24 def push(name, backend) exists?(name) @backends.push([name, backend]) end |
#unshift(name, backend) ⇒ Object
30 31 32 33 |
# File 'lib/blueprint_config/backend_collection.rb', line 30 def unshift(name, backend) exists?(name) @backends.unshift([name, backend]) end |