dry-stack 0.1.9 → 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: a5010fb1f68c965e46cfc971af6bc8cd51396b4ba0d536a941d05a8b1c57ad9e
4
- data.tar.gz: c1969aae21a128f7f6258bb40de6da55870d5cf2e111102d3dcde9783a07c372
3
+ metadata.gz: ee77026f4dbbad4d93821303e117f494ca9ee63277d6ac75f9ee4bd4bf8f85f3
4
+ data.tar.gz: 115fd41b201a1483b0485639309e06f132f1247a7712f8c4a49ed26197ef3fa9
5
5
  SHA512:
6
- metadata.gz: f8b7e31c2c065ddb71b39aac76abaf0cd669c862eeebf5f9b2504ea76722e67a9d7bc0f2e98a68120c3ac6ef66d5c46d8d843a1eafa3f1d37d6a6f7809f4d213
7
- data.tar.gz: e4aa2c968ecec428dfe77fd5bb1813e2dd3330720da92b279b659062b141eb5ac41364f873f27f6e8591899429df7ef16f88483422b21a74f777eee6756ebf4b
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
 
@@ -31,7 +31,7 @@ module Dry
31
31
  end
32
32
  end
33
33
 
34
- def each_recursive(parent, each_ =-> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk)
34
+ def each_recursive(parent, each_ = -> { _1.respond_to?(:each) ? _1.each : [] }, path = [], &blk)
35
35
  each2_ = each_.is_a?(Array) ? ->(p) { (m = each_.find { p.respond_to? _1 }) ? p.send(m) : [] } : each_
36
36
  (each2_[parent] || []).each do |(k,v)|
37
37
  blk.call [path + [parent], k, v, path]
@@ -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,13 +336,19 @@ module Dry
332
336
  (@after_blocks ||=[]) << block
333
337
  end
334
338
 
335
- # TODO: latter
336
- # def ServicesEach(names, &)
337
- # def ServicesEach(names, opts, &)
338
- def ServicesEach(&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)
339
347
  After do
340
- @services.values.each do |svc|
341
- ServiceFunction.new(svc, &block) if block_given?
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
342
352
  end
343
353
  end
344
354
  end
@@ -347,13 +357,28 @@ module Dry
347
357
  @publish_ports.merge! ports.to_h { |k, v| [k,[v].flatten] }
348
358
  end
349
359
 
350
- 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 = {}, &)
375
+ opts = opts.dup
351
376
  opts[:ports] = [opts[:ports]].flatten if opts.key? :ports
352
377
  opts[:environment] = opts.delete(:env) if opts.key? :env
353
378
 
354
379
  service = @services[name.to_sym] ||= {environment: {}, deploy: {labels: []}}
355
- service.merge! opts
356
- ServiceFunction.new(service, &) if block_given?
380
+ service.deep_merge! opts
381
+ ServiceFunction.new(service, &) if block_given?
357
382
  end
358
383
 
359
384
  def Description(string)
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Stack
3
- VERSION = '0.1.9'
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.9
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