Class: Kuby::Docker::LayerStack
- Inherits:
-
Object
- Object
- Kuby::Docker::LayerStack
- Extended by:
- T::Generic, T::Sig
- Includes:
- Enumerable
- Defined in:
- lib/kuby/docker/layer_stack.rb
Constant Summary collapse
- Elem =
type_member(fixed: Layer)
Instance Attribute Summary collapse
-
#layers ⇒ Object
readonly
Returns the value of attribute layers.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #delete(name) ⇒ Object
- #each(&block) ⇒ Object
- #includes?(name) ⇒ Boolean
-
#initialize ⇒ LayerStack
constructor
A new instance of LayerStack.
- #insert(name, layer = nil, options = {}, &block) ⇒ Object
- #use(name, layer = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ LayerStack
Returns a new instance of LayerStack.
20 21 22 23 |
# File 'lib/kuby/docker/layer_stack.rb', line 20 def initialize @stack = T.let([], T::Array[Symbol]) @layers = T.let({}, T::Hash[Symbol, Layer]) end |
Instance Attribute Details
#layers ⇒ Object (readonly)
Returns the value of attribute layers.
17 18 19 |
# File 'lib/kuby/docker/layer_stack.rb', line 17 def layers @layers end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
14 15 16 |
# File 'lib/kuby/docker/layer_stack.rb', line 14 def stack @stack end |
Instance Method Details
#delete(name) ⇒ Object
98 99 100 101 |
# File 'lib/kuby/docker/layer_stack.rb', line 98 def delete(name) stack.delete(name) layers.delete(name) end |
#each(&block) ⇒ Object
31 32 33 34 |
# File 'lib/kuby/docker/layer_stack.rb', line 31 def each(&block) return to_enum(T.must(__method__)) unless block_given? @stack.each { |name| yield T.must(layers[name]) } end |
#includes?(name) ⇒ Boolean
104 105 106 |
# File 'lib/kuby/docker/layer_stack.rb', line 104 def includes?(name) layers.include?(name) end |
#insert(name, layer = nil, options = {}, &block) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/kuby/docker/layer_stack.rb', line 65 def insert(name, layer = nil, = {}, &block) # this is truly gross but it's the only way I can think of to be able # to call insert these two ways: # # insert :foo, FooLayer.new, before: :bundler_phase # insert :foo, before: :bundler_phase do # ... # end if layer.is_a?(Hash) insert(name, nil, .merge(layer), &block) return end existing_name = [:before] || [:after] idx = stack.index(existing_name) unless idx raise ArgumentError, "Could not find existing layer '#{existing_name}'" end idx += 1 if [:after] stack.insert(idx, name) if layer layers[name] = layer elsif block_given? layers[name] = InlineLayer.new(block) else raise "Must either pass a layer object or a block to `#{__method__}'" end end |
#use(name, layer = nil, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kuby/docker/layer_stack.rb', line 44 def use(name, layer = nil, &block) stack << name if layer layers[name] = layer elsif block_given? layers[name] = InlineLayer.new(block) else raise "Must either pass a layer object or a block to `#{__method__}'" end end |