k_director 0.11.3 → 0.12.0

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: 30dd3c3e965fcfffe2f5a1bed60503f7bce7d81ebbb6e8222a839cdb12158a00
4
- data.tar.gz: 3dc4f966e719adf8bb9c360034484dbb9592d3738a4a1bfc5d11cfd40c310619
3
+ metadata.gz: 61ab15797b459bd3b8a2938801a016638c268ef5339cd5df1a5a4a7985c255cd
4
+ data.tar.gz: d8670419a2617533e13c8ad2eef7e1f74b412ee780c119550f670d850b6f9897
5
5
  SHA512:
6
- metadata.gz: 4a6b899015103ceb4781ddffb7027e8f854dbc9a004bb8f4a5b28f1192e6bf53bedbd6d4a0dea501caa7afb047fbbf6b6c9e65462ddf24ba94e879d01c8e5e87
7
- data.tar.gz: a87a0fe0a07591a0f39a244e7287e21999bea92e819382a2f6e3899af73a917d348f13917c1fd7918d53cc5047f768b40b459722aac1e3ad1e8bbc2a5ae04bb3
6
+ metadata.gz: 67eabf548f77d0d21d444b8186304054fe097195ce78a7f5d8e0ccc072dd04b16a05d59a43956d287c2045e3fe2aeb8a9ba778442c2620dd1ff9668b503968a0
7
+ data.tar.gz: c29f1c1d1440a5de7d3081cefd7463efcd4d6d8d95020d72a3efab8f71c25c5ee7ba0fceb0b9e76d2a5eb372a0459080299d9952a82cb19ea3ed3cca2ad26202
data/docs/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.11.3](https://github.com/klueless-io/k_director/compare/v0.11.2...v0.11.3) (2022-02-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add simple dsl ([0fd61ab](https://github.com/klueless-io/k_director/commit/0fd61abbe90a136c96b750fcf7456bc46aa73463))
7
+
1
8
  ## [0.11.2](https://github.com/klueless-io/k_director/compare/v0.11.1...v0.11.2) (2022-02-08)
2
9
 
3
10
 
@@ -3,18 +3,13 @@
3
3
  module KDirector
4
4
  module Builders
5
5
  # Actions document builder
6
- class ActionsBuilder
6
+ class ActionsBuilder < KDirector::Builders::DomBuilder
7
7
  attr_reader :actions
8
- attr_reader :dom
9
8
  attr_reader :last_action
10
9
 
11
- def initialize
12
- reset
13
- end
14
-
15
10
  def reset
11
+ super
16
12
  @actions = []
17
- @dom = {}
18
13
  @last_action = {}
19
14
  end
20
15
 
@@ -23,100 +18,12 @@ module KDirector
23
18
  @last_action = action
24
19
  end
25
20
 
26
- # Set many key/value pairs gainst a group
27
- #
28
- # example:
29
- # set_many(:github, repo_name: 'repo-name', organization: 'org-name')
30
- def group_set(group = nil, **opts)
31
- return if group.nil? && opts.empty?
32
-
33
- if group.nil?
34
- opts.each do |key, value|
35
- set(key, value)
36
- end
37
- else
38
- dom[group] = {} if opts.empty? # initialize the group name if no options are provided
39
- opts.each do |key, value|
40
- set(group, key, value)
41
- end
42
- end
43
- end
44
-
45
- # set key_set/value pair, can be used for
46
- #
47
- # - simple key/value pairs
48
- # - initialize key/array pairs
49
- #
50
- # example:
51
- # set(:a, 1)
52
- # set(:a, [])
53
- # set(:a, [1, 2, 3])
54
- # set(:a, some_value, default_value: 'use if not supplied')
55
- # set(:a, :b, 'nested value')
56
- # set(:a, :b, :c, 'deeply nested value')
57
- # set(:a, :b, :c, :d, :e, :f, 'depth is no barrier')
58
- def set(*keyset_value, default_value: nil)
59
- size = keyset_value.size
60
-
61
- raise ArgumentError, 'set requires 2 or more arguments' if size < 2
62
-
63
- target = initialize_hierarchy(keyset_value)
64
-
65
- set_kv(target, keyset_value[size - 2], keyset_value[size - 1], default_value: default_value)
66
- end
67
-
68
- # add value to array
69
- # set(:a, [])
70
- # add(:a, 1])
71
- # add(:a, 2])
72
- # add(:a, 3])
73
- def add(*keyset_value, default_value: nil)
74
- size = keyset_value.size
75
-
76
- raise ArgumentError, 'add requires 2 or more arguments' if size < 2
77
-
78
- target = initialize_hierarchy(keyset_value)
79
-
80
- add_kv(target, keyset_value[size - 2], keyset_value[size - 1], default_value: default_value)
81
- end
82
-
83
21
  def debug
84
22
  puts JSON.pretty_generate(actions)
85
- puts JSON.pretty_generate(dom)
86
- # log.structure(dom)
23
+ super
87
24
 
88
25
  self
89
26
  end
90
-
91
- def build
92
- # hook into the set, add and queue_action methods form memoization
93
- KUtil.data.to_open_struct(@dom)
94
- end
95
-
96
- private
97
-
98
- def initialize_hierarchy(keys_value)
99
- target = @dom
100
-
101
- return target unless keys_value.size > 2
102
-
103
- keys_value.slice(0..-3).each_with_index do |key, _index|
104
- target[key] = {} unless target.key?(key)
105
- target = target[key]
106
- end
107
- target
108
- end
109
-
110
- def set_kv(target, key, value, default_value: nil)
111
- set_value = value.nil? ? default_value : value
112
- target[key] = set_value
113
- end
114
-
115
- def add_kv(target, key, value, default_value: nil)
116
- add_value = value.nil? ? default_value : value
117
- target[key] = [] unless target.key?(key)
118
- target[key] << add_value
119
- end
120
27
  end
121
28
  end
122
29
  end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KDirector
4
+ module Builders
5
+ # Dom builder
6
+ class DomBuilder
7
+ attr_reader :dom
8
+
9
+ def initialize
10
+ reset
11
+ end
12
+
13
+ def reset
14
+ @dom = {}
15
+ end
16
+
17
+ # Set many key/value pairs gainst a group
18
+ #
19
+ # example:
20
+ # set_many(:github, repo_name: 'repo-name', organization: 'org-name')
21
+ def group_set(group = nil, **opts)
22
+ return if group.nil? && opts.empty?
23
+
24
+ if group.nil?
25
+ opts.each do |key, value|
26
+ set(key, value)
27
+ end
28
+ else
29
+ dom[group] = {} if opts.empty? # initialize the group name if no options are provided
30
+ opts.each do |key, value|
31
+ set(group, key, value)
32
+ end
33
+ end
34
+ end
35
+
36
+ # set key_set/value pair, can be used for
37
+ #
38
+ # - simple key/value pairs
39
+ # - initialize key/array pairs
40
+ #
41
+ # example:
42
+ # set(:a, 1)
43
+ # set(:a, [])
44
+ # set(:a, [1, 2, 3])
45
+ # set(:a, some_value, default_value: 'use if not supplied')
46
+ # set(:a, :b, 'nested value')
47
+ # set(:a, :b, :c, 'deeply nested value')
48
+ # set(:a, :b, :c, :d, :e, :f, 'depth is no barrier')
49
+ def set(*keyset_value, default_value: nil)
50
+ size = keyset_value.size
51
+
52
+ raise ArgumentError, 'set requires 2 or more arguments' if size < 2
53
+
54
+ target = initialize_hierarchy(keyset_value)
55
+
56
+ set_kv(target, keyset_value[size - 2], keyset_value[size - 1], default_value: default_value)
57
+ end
58
+
59
+ # add value to array
60
+ # set(:a, [])
61
+ # add(:a, 1])
62
+ # add(:a, 2])
63
+ # add(:a, 3])
64
+ def add(*keyset_value, default_value: nil)
65
+ size = keyset_value.size
66
+
67
+ raise ArgumentError, 'add requires 2 or more arguments' if size < 2
68
+
69
+ target = initialize_hierarchy(keyset_value)
70
+
71
+ add_kv(target, keyset_value[size - 2], keyset_value[size - 1], default_value: default_value)
72
+ end
73
+
74
+ def debug
75
+ puts JSON.pretty_generate(dom)
76
+ # log.structure(dom)
77
+
78
+ self
79
+ end
80
+
81
+ def build
82
+ # hook into the set, add and queue_action methods form memoization
83
+ KUtil.data.to_open_struct(@dom)
84
+ end
85
+
86
+ private
87
+
88
+ def initialize_hierarchy(keys_value)
89
+ target = @dom
90
+
91
+ return target unless keys_value.size > 2
92
+
93
+ keys_value.slice(0..-3).each_with_index do |key, _index|
94
+ target[key] = {} unless target.key?(key)
95
+ target = target[key]
96
+ end
97
+ target
98
+ end
99
+
100
+ def set_kv(target, key, value, default_value: nil)
101
+ set_value = value.nil? ? default_value : value
102
+ target[key] = set_value
103
+ end
104
+
105
+ def add_kv(target, key, value, default_value: nil)
106
+ add_value = value.nil? ? default_value : value
107
+ target[key] = [] unless target.key?(key)
108
+ target[key] << add_value
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KDirector
4
- VERSION = '0.11.3'
4
+ VERSION = '0.12.0'
5
5
  end
data/lib/k_director.rb CHANGED
@@ -7,6 +7,7 @@ require 'k_builder'
7
7
  require 'k_ext/github'
8
8
 
9
9
  require_relative 'k_director/version'
10
+ require_relative 'k_director/builders/dom_builder'
10
11
  require_relative 'k_director/builders/actions_builder'
11
12
  require_relative 'k_director/directors/base_director'
12
13
  require_relative 'k_director/directors/child_director'
data/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "k_director",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "k_director",
9
- "version": "0.11.3",
9
+ "version": "0.12.0",
10
10
  "devDependencies": {
11
11
  "@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
12
12
  "@semantic-release/changelog": "^6.0.1",
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k_director",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "description": "Command line and CI/CD tools for k_director",
5
5
  "scripts": {
6
6
  "release": "semantic-release"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_director
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_config
@@ -113,6 +113,7 @@ files:
113
113
  - k_director.gemspec
114
114
  - lib/k_director.rb
115
115
  - lib/k_director/builders/actions_builder.rb
116
+ - lib/k_director/builders/dom_builder.rb
116
117
  - lib/k_director/directors/base_director.rb
117
118
  - lib/k_director/directors/child_director.rb
118
119
  - lib/k_director/directors/data.rb