orchparty 1.0.1 → 1.1.0
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 +4 -4
- data/lib/deep_merge.rb +1 -1
- data/lib/orchparty/ast.rb +32 -0
- data/lib/orchparty/cli.rb +2 -0
- data/lib/orchparty/context.rb +10 -0
- data/lib/orchparty/dsl_parser.rb +30 -29
- data/lib/orchparty/transformations/all.rb +1 -2
- data/lib/orchparty/transformations/mixin.rb +7 -7
- data/lib/orchparty/transformations/variable.rb +8 -2
- data/lib/orchparty/transformations.rb +2 -2
- data/lib/orchparty/version.rb +1 -1
- data/lib/orchparty.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7e581687a4faa39cef9b1fc4bd506bcb6cbb1d2
|
4
|
+
data.tar.gz: 39511e9ed35643a39a17efed0d5151c1fb825c07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f987a1868610bc273afa776e1086724693d35665b92ad5ee7ec86c1da23bd70a72fae1fab04be291ed7a90af586d77ce7acb0d0e789099ed712f20dffc797ce
|
7
|
+
data.tar.gz: d93ef5d2793ff2b441751ff391dd48fe9079737161d192b04132858e9f27d39c8cee19748ddd782f19d261bab6c206a9fba17bc18057babe53bcf0fd03042701
|
data/lib/deep_merge.rb
CHANGED
@@ -131,7 +131,7 @@ module Hashie
|
|
131
131
|
hash[k] = if hash.key?(k) && hash[k].is_a?(::Hash) && v.is_a?(::Hash)
|
132
132
|
_recursive_merge(hash[k], v, &block)
|
133
133
|
elsif hash.key?(k) && hash[k].is_a?(::Array) && v.is_a?(::Array)
|
134
|
-
hash[k].concat(v)
|
134
|
+
hash[k].concat(v).uniq
|
135
135
|
else
|
136
136
|
if hash.key?(k) && block_given?
|
137
137
|
block.call(k, hash[k], v)
|
data/lib/orchparty/ast.rb
CHANGED
@@ -8,5 +8,37 @@ module Orchparty
|
|
8
8
|
include Hashie::Extensions::MethodAccess
|
9
9
|
include Hashie::Extensions::Mash::KeepOriginalKeys
|
10
10
|
end
|
11
|
+
|
12
|
+
def self.hash(args = {})
|
13
|
+
Node.new.merge(args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.array(args = [])
|
17
|
+
args
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.root(args = {})
|
21
|
+
Node.new(applications: {}, _mixins: {}).merge(args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.mixin(args = {})
|
25
|
+
Node.new({services: {}, _mixins: {}, volumes: {}, _variables: {}, networks: {}}).merge(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.application(args = {})
|
29
|
+
Node.new({services: {}, _mixins: {}, _mix:[], volumes: {}, _variables: {}, networks: {}}).merge(args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.all(args = {})
|
33
|
+
Node.new(_mix:[], _variables: {}).merge(args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.application_mixin(args = {})
|
37
|
+
Node.new(_mix:[], _variables: {}).merge(args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.service(args = {})
|
41
|
+
Node.new(_mix:[], _variables: {}).merge(args)
|
42
|
+
end
|
11
43
|
end
|
12
44
|
end
|
data/lib/orchparty/cli.rb
CHANGED
@@ -18,11 +18,13 @@ class OrchPartyApp
|
|
18
18
|
com.command(name) do |plugin_command|
|
19
19
|
plugin_command.flag [:filename,:f,'file-name'], required: true, :desc => 'The Orchparty input file'
|
20
20
|
plugin_command.flag [:application,:a], required: true, :desc => 'The application that should be compiled'
|
21
|
+
plugin_command.switch :"force-variable-definition", :default_value => false, :desc => "Raises an Error if the input contains a not defined variable"
|
21
22
|
plugin.define_flags(plugin_command)
|
22
23
|
plugin_command.action do |global_options,plugin_options,args|
|
23
24
|
options = plugin_options.delete(GLI::Command::PARENT)
|
24
25
|
options[:application] = plugin_options[:application]
|
25
26
|
options[:filename] = plugin_options[:filename]
|
27
|
+
options[:force_variable_definition] = plugin_options[:"force-variable-definition"]
|
26
28
|
Orchparty.generate(name, options, plugin_options)
|
27
29
|
end
|
28
30
|
end
|
data/lib/orchparty/context.rb
CHANGED
@@ -5,6 +5,16 @@ module Orchparty
|
|
5
5
|
include Hashie::Extensions::MethodAccess
|
6
6
|
include Hashie::Extensions::Mash::KeepOriginalKeys
|
7
7
|
|
8
|
+
|
9
|
+
def method_missing(name, *args)
|
10
|
+
raise "#{name} not declared for #{application.name}.#{service.name}" if @_force_variable_definition && !key?(name) && !key?(name.to_s)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def _force_variable_definition=(v)
|
15
|
+
@_force_variable_definition = v
|
16
|
+
end
|
17
|
+
|
8
18
|
def context
|
9
19
|
self
|
10
20
|
end
|
data/lib/orchparty/dsl_parser.rb
CHANGED
@@ -26,7 +26,7 @@ module Orchparty
|
|
26
26
|
class RootBuilder < Builder
|
27
27
|
|
28
28
|
def initialize
|
29
|
-
@root = AST
|
29
|
+
@root = AST.root
|
30
30
|
end
|
31
31
|
|
32
32
|
def import(rel_file)
|
@@ -43,7 +43,7 @@ module Orchparty
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def mixin(name, &block)
|
46
|
-
@root.
|
46
|
+
@root._mixins[name] = MixinBuilder.build(name, block)
|
47
47
|
self
|
48
48
|
end
|
49
49
|
|
@@ -55,22 +55,18 @@ module Orchparty
|
|
55
55
|
class MixinBuilder < Builder
|
56
56
|
|
57
57
|
def initialize(name)
|
58
|
-
@mixin = AST
|
59
|
-
services: {},
|
60
|
-
mixins: {},
|
61
|
-
volumes: {},
|
62
|
-
networks: {})
|
58
|
+
@mixin = AST.mixin(name: name)
|
63
59
|
end
|
64
60
|
|
65
61
|
def service(name, &block)
|
66
62
|
result = ServiceBuilder.build(name, block)
|
67
63
|
@mixin.services[name] = result
|
68
|
-
@mixin.
|
64
|
+
@mixin._mixins[name] = result
|
69
65
|
self
|
70
66
|
end
|
71
67
|
|
72
68
|
def mixin(name, &block)
|
73
|
-
@mixin.
|
69
|
+
@mixin._mixins[name] = ServiceBuilder.build(name, block)
|
74
70
|
end
|
75
71
|
|
76
72
|
def volumes(&block)
|
@@ -89,19 +85,15 @@ module Orchparty
|
|
89
85
|
class ApplicationBuilder < Builder
|
90
86
|
|
91
87
|
def initialize(name)
|
92
|
-
@application = AST
|
93
|
-
services: {},
|
94
|
-
mix: [],
|
95
|
-
mixins: {},
|
96
|
-
volumes: {})
|
88
|
+
@application = AST.application(name: name)
|
97
89
|
end
|
98
90
|
|
99
91
|
def mix(name)
|
100
|
-
@application.
|
92
|
+
@application._mix << name
|
101
93
|
end
|
102
94
|
|
103
95
|
def mixin(name, &block)
|
104
|
-
@application.
|
96
|
+
@application._mixins[name] = ApplicationMixinBuilder.build(block)
|
105
97
|
self
|
106
98
|
end
|
107
99
|
|
@@ -140,20 +132,20 @@ module Orchparty
|
|
140
132
|
if block_given?
|
141
133
|
value = HashBuilder.build(block)
|
142
134
|
if values.count == 1
|
143
|
-
@hash ||=
|
135
|
+
@hash ||= AST.hash
|
144
136
|
@hash[values.first.to_sym] = value
|
145
137
|
else
|
146
|
-
@hash ||=
|
138
|
+
@hash ||= AST.array
|
147
139
|
@hash << value
|
148
140
|
end
|
149
141
|
else
|
150
142
|
value = values.first
|
151
143
|
if value.is_a? Hash
|
152
|
-
@hash ||=
|
144
|
+
@hash ||= AST.hash
|
153
145
|
key, value = value.first
|
154
146
|
@hash[key.to_sym] = value
|
155
147
|
else
|
156
|
-
@hash ||=
|
148
|
+
@hash ||= AST.array
|
157
149
|
@hash << value
|
158
150
|
end
|
159
151
|
end
|
@@ -161,45 +153,54 @@ module Orchparty
|
|
161
153
|
end
|
162
154
|
|
163
155
|
def _build
|
164
|
-
@hash
|
156
|
+
@hash
|
165
157
|
end
|
166
158
|
end
|
167
159
|
|
168
160
|
class CommonBuilder < Builder
|
169
161
|
|
170
|
-
def initialize
|
171
|
-
@
|
162
|
+
def initialize(node)
|
163
|
+
@node = node
|
172
164
|
end
|
173
165
|
|
174
166
|
def mix(name)
|
175
|
-
@
|
167
|
+
@node._mix << name
|
176
168
|
end
|
177
169
|
|
178
170
|
def method_missing(name, *values, &block)
|
179
171
|
if block_given?
|
180
|
-
@
|
172
|
+
@node[name] = HashBuilder.build(block)
|
181
173
|
else
|
182
|
-
@
|
174
|
+
@node[name] = values.first
|
183
175
|
end
|
184
176
|
end
|
185
177
|
|
186
178
|
def _build
|
187
|
-
@
|
179
|
+
@node
|
188
180
|
end
|
189
181
|
|
190
182
|
def variables(&block)
|
191
|
-
@
|
183
|
+
@node._variables = HashBuilder.build(block)
|
192
184
|
self
|
193
185
|
end
|
194
186
|
end
|
195
187
|
|
196
188
|
class AllBuilder < CommonBuilder
|
189
|
+
def initialize
|
190
|
+
super AST.all
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class ApplicationMixinBuilder < CommonBuilder
|
195
|
+
def initialize
|
196
|
+
super AST.application_mixin
|
197
|
+
end
|
197
198
|
end
|
198
199
|
|
199
200
|
class ServiceBuilder < CommonBuilder
|
200
201
|
|
201
202
|
def initialize(name)
|
202
|
-
|
203
|
+
super AST.service(name: name)
|
203
204
|
end
|
204
205
|
end
|
205
206
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Orchparty
|
3
2
|
module Transformations
|
4
3
|
class All
|
@@ -6,7 +5,7 @@ module Orchparty
|
|
6
5
|
ast.applications.each do |_, application|
|
7
6
|
application.services.transform_values! do |service|
|
8
7
|
if application.all.is_a?(Hash)
|
9
|
-
AST
|
8
|
+
AST.service(application.all.deep_merge_concat(service))
|
10
9
|
else
|
11
10
|
service
|
12
11
|
end
|
@@ -3,9 +3,9 @@ module Orchparty
|
|
3
3
|
class Mixin
|
4
4
|
def transform(ast)
|
5
5
|
ast.applications.transform_values! do |application|
|
6
|
-
current = AST
|
7
|
-
application.
|
8
|
-
mixin = application.
|
6
|
+
current = AST.application
|
7
|
+
application._mix.each do |mixin_name|
|
8
|
+
mixin = application._mixins[mixin_name] || ast._mixins[mixin_name]
|
9
9
|
current = current.deep_merge_concat(mixin)
|
10
10
|
end
|
11
11
|
transform_application(current.deep_merge_concat(application), ast)
|
@@ -15,7 +15,7 @@ module Orchparty
|
|
15
15
|
|
16
16
|
def transform_application(application, ast)
|
17
17
|
application.services = application.services.transform_values! do |service|
|
18
|
-
current = AST
|
18
|
+
current = AST.service
|
19
19
|
service.delete(:_mix).each do |mix|
|
20
20
|
mixin = transform_mixin(resolve_mixin(mix, application, ast), application, ast)
|
21
21
|
current = current.deep_merge_concat(mixin)
|
@@ -28,14 +28,14 @@ module Orchparty
|
|
28
28
|
def resolve_mixin(mix, application, ast)
|
29
29
|
if mix.include? "."
|
30
30
|
mixin_name, mixin_service_name = mix.split(".")
|
31
|
-
ast.
|
31
|
+
ast._mixins[mixin_name]._mixins[mixin_service_name]
|
32
32
|
else
|
33
|
-
application.
|
33
|
+
application._mixins[mix]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
def transform_mixin(mixin, application, ast)
|
38
|
-
current = AST
|
38
|
+
current = AST.application_mixin
|
39
39
|
mixin[:_mix].each do |mix|
|
40
40
|
current = current.deep_merge_concat(resolve_mixin(mix, application, ast))
|
41
41
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
-
|
2
1
|
module Orchparty
|
3
2
|
module Transformations
|
4
3
|
class Variable
|
4
|
+
|
5
|
+
def initialize(opts = {})
|
6
|
+
@force_variable_definition = opts[:force_variable_definition]
|
7
|
+
end
|
8
|
+
|
5
9
|
def transform(ast)
|
6
10
|
ast.applications.each do |_, application|
|
7
11
|
application.services = application.services.each do |_, service|
|
@@ -32,7 +36,9 @@ module Orchparty
|
|
32
36
|
def build_context(application:, service:)
|
33
37
|
application._variables ||= {}
|
34
38
|
variables = application._variables.merge(service._variables)
|
35
|
-
Context.new(variables.merge({application: application.merge(application._variables), service: service.merge(service._variables)}))
|
39
|
+
context = Context.new(variables.merge({application: application.merge(application._variables), service: service.merge(service._variables)}))
|
40
|
+
context._force_variable_definition = @force_variable_definition
|
41
|
+
context
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -7,10 +7,10 @@ require 'orchparty/transformations/sort'
|
|
7
7
|
|
8
8
|
module Orchparty
|
9
9
|
module Transformations
|
10
|
-
def self.transform(ast)
|
10
|
+
def self.transform(ast, opts = {})
|
11
11
|
ast = All.new.transform(ast)
|
12
12
|
ast = Mixin.new.transform(ast)
|
13
|
-
ast = Variable.new.transform(ast)
|
13
|
+
ast = Variable.new(opts).transform(ast)
|
14
14
|
ast = RemoveInternal.new.transform(ast)
|
15
15
|
ast = Sort.new.transform(ast)
|
16
16
|
end
|
data/lib/orchparty/version.rb
CHANGED
data/lib/orchparty.rb
CHANGED
@@ -23,11 +23,11 @@ module Orchparty
|
|
23
23
|
Orchparty::Plugin.load_plugin(name)
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.ast(filename: , application:)
|
27
|
-
Transformations.transform(Orchparty::DSLParser.new(filename).parse).applications[application]
|
26
|
+
def self.ast(filename: , application:, force_variable_definition: nil )
|
27
|
+
Transformations.transform(Orchparty::DSLParser.new(filename).parse, force_variable_definition: force_variable_definition).applications[application]
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.generate(plugin_name, options, plugin_options)
|
31
|
-
plugins[plugin_name].generate(ast(
|
31
|
+
plugins[plugin_name].generate(ast(options), plugin_options)
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orchparty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jannis Huebl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|