dry-stack 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c88b6bc038fa30ed2b132c936cdae39d7cbc28a2fcfa0b303fc89fff05a53bb
4
- data.tar.gz: fcce7e5376b5fa037ac96c9becf52f889115636e20ba9f42a1d3f929fdc5ffec
3
+ metadata.gz: ee77026f4dbbad4d93821303e117f494ca9ee63277d6ac75f9ee4bd4bf8f85f3
4
+ data.tar.gz: 115fd41b201a1483b0485639309e06f132f1247a7712f8c4a49ed26197ef3fa9
5
5
  SHA512:
6
- metadata.gz: 255a433586527977da9d6ff9f7c579bcd646adc91c0616eb09345f55c8e715eb8d430939331013a651b369cf3c8eb8e56bd5552b7430916e31d3a0846d760e77
7
- data.tar.gz: 9b749419d4c4ec2fe4b7ad330e7a3fddcd500757cd025ac6c90c48eafedf86708995c9f491e9e214c90feff71d48102d7e9f61820140d3980d38f25a24e5f399
6
+ metadata.gz: da8b13fa2ede538ad057ff761e5a66c9764e4c246581687bdafafbe6f7783fe036c3b1ff4580032a4fc103b4e2ff936a4001b62efa16b4be1342fb421ffb9969
7
+ data.tar.gz: 75fd19165a78349b402fd32c1a913c5b0697e833a448de9284e890657e7f9ea2c1aab94f281f877e6afcb51ada962c49eb485f88e0ea9941f265d2a94f0ff4fa
@@ -40,7 +40,6 @@ module Dry
40
40
  def safe_eval(drs, params)
41
41
  Dry::Stack(params[:name], params[:configuration]) do
42
42
  eval drs, self.binding
43
- @after_blocks&.each { instance_exec &_1 }
44
43
  end
45
44
  end
46
45
 
@@ -45,6 +45,10 @@ module Dry
45
45
  def Stack(name = nil, configuration = nil, &)
46
46
  Stack.last_stack = Stack.new name
47
47
  Stack.last_stack.instance_exec(&) if block_given?
48
+ Stack.last_stack.instance_exec do
49
+ @services_blocks&.each { instance_exec &_1 }
50
+ @after_blocks&.each { instance_exec &_1 }
51
+ end
48
52
  Stack.last_stack.apply_configuration configuration if configuration
49
53
  end
50
54
 
@@ -147,7 +151,7 @@ module Dry
147
151
 
148
152
  compose[:services].each do |name, service|
149
153
 
150
- service[:image].gsub!(/:latest$/, '') # let docker swarm to create tag: :latest@sha265:0000...
154
+ service[:image].gsub!(/:latest$/, '') if service[:image] # let docker swarm to create tag: :latest@sha265:0000...
151
155
 
152
156
  ingress = [@ingress[name], service[:ingress] || [] ].flatten.compact
153
157
 
@@ -332,11 +336,19 @@ module Dry
332
336
  (@after_blocks ||=[]) << block
333
337
  end
334
338
 
335
- def ServicesEach(name = nil, opts = {}, &block)
339
+ def BeforeService(name = nil, opts = {}, &block)
340
+ (@before_blocks ||=[]).push names: [name].flatten.compact, except: opts[:except],
341
+ block: ->(s_name) {
342
+ _ServiceImplementation s_name, opts, &block
343
+ }
344
+ end
345
+
346
+ def AfterService(name = nil, opts = {}, &block)
336
347
  After do
337
- name ||= @services.keys
338
- [name].flatten.each do |s_name|
339
- Service s_name, opts, &block
348
+ names = [name || @services.keys].flatten
349
+ names -= [opts[:except]].flatten if opts.key? :except
350
+ names.each do |s_name|
351
+ _ServiceImplementation s_name, opts, &block
340
352
  end
341
353
  end
342
354
  end
@@ -345,7 +357,21 @@ module Dry
345
357
  @publish_ports.merge! ports.to_h { |k, v| [k,[v].flatten] }
346
358
  end
347
359
 
348
- def Service(name, opts = {}, &)
360
+ def Service(name, opts = {}, &block)
361
+ @services_blocks ||=[]
362
+ (@services_blocks ||=[]).push -> { _ServiceDeferred(name, opts, &block) }
363
+ end
364
+
365
+ def _ServiceDeferred(name, opts = {}, &block)
366
+ (@before_blocks || []).each do |before|
367
+ next unless before[:names].empty? || before[:names].include?(name)
368
+ next if before[:except]&.include? name
369
+ before[:block].call(name)
370
+ end
371
+ _ServiceImplementation(name, opts, &block)
372
+ end
373
+
374
+ def _ServiceImplementation(name, opts = {}, &)
349
375
  opts = opts.dup
350
376
  opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
351
377
  opts[:environment] = opts.delete(:env) if opts.key? :env
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Stack
3
- VERSION = '0.1.10'
3
+ VERSION = '0.1.11'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake