terraspace 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 856fb06902999857dcda1fd2a82709f7f01487a1b94420361cc7c7474df81c3e
4
- data.tar.gz: cc60137b36d9a25928b410f2ef4b65467647674a378e8732e6c55e90d2e246ca
3
+ metadata.gz: f265061c3973d32dcbea50e12b291ee22041dc2e5bc2cf2521907dd4d74b0703
4
+ data.tar.gz: 97e6064b47fe37f11660fe05512e1750b23f96cd7bc7ea1bef0aa512884922de
5
5
  SHA512:
6
- metadata.gz: 644e41b44f03afcaab0c6e261b7021811da19dc24d8e16d1a96fbd6516d84fc714b5fe9d6a9a0042a323a0c4919561e3236c6a3979b1d0132c850309d0eb2763
7
- data.tar.gz: a74a1d2c00910e3214fc373bb21b2ccdec57f41ab628fe123ba45816ae165d875bfa543057dea518ee6457e7a1bdbc39f6dfa4e7d32e3794270d2c3153b2d17b
6
+ metadata.gz: bb0ccae4efe36fae839a755561e9b6829b998c4ec653f7a9a24c8a67a6e9da9ff9e5b81ad1134018edceed75b5859e12cce280819e2792a203da7a65f4997087
7
+ data.tar.gz: '0269f857a01274f4c9b64b051c724fff030582e2d62b9222da04ae0828e7770160645a4dee01a0a0c791921197d08ce87f420e5fa24678e961e76fb267c9377b'
data/CHANGELOG.md CHANGED
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.0.4] - 2022-01-21
7
+ - [#193](https://github.com/boltops-tools/terraspace/pull/193) improve all include_stacks and exclude_stacks option
8
+
6
9
  ## [1.0.3] - 2022-01-20
7
10
  - [#192](https://github.com/boltops-tools/terraspace/pull/192) run super-early boot hooks before dotenv load
8
11
 
@@ -1,28 +1,84 @@
1
1
  module Terraspace::Compiler
2
2
  class Select
3
+ include Terraspace::Util::Logging
4
+
3
5
  def initialize(path)
4
6
  @path = path
5
7
  @stack_name = extract_stack_name(path)
6
8
  end
7
9
 
8
10
  def selected?
9
- all = Terraspace.config.all
10
- # Key difference between include_stacks vs all.include_stacks option is that
11
- # the option can be nil. The local variable is guaranteed to be an Array.
12
- # This simplifies the logic.
13
- include_stacks = all.include_stacks || []
14
- ignore_stacks = all.ignore_stacks || []
15
-
16
- if all.include_stacks.nil?
17
- !ignore_stacks.include?(@stack_name)
11
+ ignore_stacks_deprecation_warning
12
+ if include_stacks.nil? && exclude_stacks.nil?
13
+ true
14
+ elsif include_stacks.nil?
15
+ !exclude_stacks.include?(@stack_name)
16
+ elsif exclude_stacks.nil?
17
+ include_stacks.include?(@stack_name)
18
18
  else
19
- stacks = include_stacks - ignore_stacks
19
+ stacks = include_stacks - exclude_stacks
20
20
  stacks.include?(@stack_name)
21
21
  end
22
22
  end
23
23
 
24
+ def include_stacks
25
+ include_option(:include_stacks)
26
+ end
27
+
28
+ def exclude_stacks
29
+ include_option(:exclude_stacks)
30
+ end
31
+
32
+ def include_option(name)
33
+ option = all[name] # IE: include_stacks or exclude_stacks
34
+ option ||= all[:ignore_stacks] if name == :exclude_stacks
35
+ case option
36
+ when nil
37
+ return nil
38
+ when Array
39
+ return option
40
+ when -> (c) { c.respond_to?(:public_instance_methods) && c.public_instance_methods.include?(:call) }
41
+ object= option.new
42
+ when -> (c) { c.respond_to?(:call) }
43
+ object = option
44
+ else
45
+ raise "Invalid option for config.all.#{name}"
46
+ end
47
+
48
+ if object
49
+ result = object.call(@stack_name)
50
+ unless result.is_a?(Array) || result.is_a?(NilClass)
51
+ message = "ERROR: The config.all.#{name} needs to return an Array or nil"
52
+ logger.info message.color(:yellow)
53
+ logger.info <<~EOL
54
+ The config.all.#{name} when assigned a class, object, or proc must implement
55
+ the call method and return an Array or nil.
56
+ The current return value is a #{result.class}
57
+ EOL
58
+ raise message
59
+ end
60
+ end
61
+ result
62
+ end
63
+
64
+ private
65
+ def all
66
+ Terraspace.config.all
67
+ end
68
+
24
69
  def extract_stack_name(path)
25
70
  path.sub(%r{.*(app|vendor)/stacks/}, '')
26
71
  end
72
+
73
+ @@ignore_stacks_deprecation_warning = nil
74
+ def ignore_stacks_deprecation_warning
75
+ return unless all.ignore_stacks
76
+ return if @@ignore_stacks_deprecation_warning
77
+ puts <<~EOL.color(:yellow)
78
+ DEPRECATED: config.all.ignore_stacks
79
+ Instead use: config.all.exclude_stacks
80
+ EOL
81
+ @@ignore_stacks_deprecation_warning = true
82
+ end
27
83
  end
28
84
  end
@@ -1,3 +1,3 @@
1
1
  module Terraspace
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport