dtk-dsl 1.0.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 +7 -0
- data/.byebug_history +70 -0
- data/.gitignore +2 -0
- data/Gemfile +2 -0
- data/README.md +2 -0
- data/dtk-dsl.gemspec +16 -0
- data/lib/dsl/directory_generator.rb +27 -0
- data/lib/dsl/directory_parser/path_info.rb +62 -0
- data/lib/dsl/directory_parser.rb +33 -0
- data/lib/dsl/dsl_version.rb +36 -0
- data/lib/dsl/error/subclasses.rb +38 -0
- data/lib/dsl/error.rb +24 -0
- data/lib/dsl/file_generator/content_input/array.rb +31 -0
- data/lib/dsl/file_generator/content_input/hash.rb +53 -0
- data/lib/dsl/file_generator/content_input/mixin.rb +68 -0
- data/lib/dsl/file_generator/content_input/string.rb +31 -0
- data/lib/dsl/file_generator/content_input/tags.rb +87 -0
- data/lib/dsl/file_generator/content_input.rb +29 -0
- data/lib/dsl/file_generator/yaml_object.rb +24 -0
- data/lib/dsl/file_generator.rb +39 -0
- data/lib/dsl/file_obj.rb +119 -0
- data/lib/dsl/file_parser/input/array.rb +27 -0
- data/lib/dsl/file_parser/input/hash.rb +40 -0
- data/lib/dsl/file_parser/input.rb +29 -0
- data/lib/dsl/file_parser/output.rb +24 -0
- data/lib/dsl/file_parser.rb +71 -0
- data/lib/dsl/file_type.rb +79 -0
- data/lib/dsl/input_output_common/array.rb +43 -0
- data/lib/dsl/input_output_common/canonical/array.rb +27 -0
- data/lib/dsl/input_output_common/canonical/hash.rb +69 -0
- data/lib/dsl/input_output_common/canonical/hash_key.rb +54 -0
- data/lib/dsl/input_output_common/canonical.rb +28 -0
- data/lib/dsl/input_output_common/hash.rb +44 -0
- data/lib/dsl/input_output_common/output_class_mixin.rb +34 -0
- data/lib/dsl/input_output_common/semantic_parse/hash.rb +33 -0
- data/lib/dsl/input_output_common/semantic_parse/mixin.rb +44 -0
- data/lib/dsl/input_output_common/semantic_parse.rb +26 -0
- data/lib/dsl/input_output_common.rb +60 -0
- data/lib/dsl/qualified_key.rb +55 -0
- data/lib/dsl/template/constant_class_mixin.rb +91 -0
- data/lib/dsl/template/generation/class_mixin.rb +40 -0
- data/lib/dsl/template/generation/mixin.rb +134 -0
- data/lib/dsl/template/generation.rb +26 -0
- data/lib/dsl/template/loader.rb +66 -0
- data/lib/dsl/template/parsing/class_mixin.rb +67 -0
- data/lib/dsl/template/parsing/mixin.rb +214 -0
- data/lib/dsl/template/parsing/parent_key.rb +82 -0
- data/lib/dsl/template/parsing/parsing_error/subclasses.rb +62 -0
- data/lib/dsl/template/parsing/parsing_error.rb +52 -0
- data/lib/dsl/template/parsing.rb +29 -0
- data/lib/dsl/template/v1/assembly.rb +82 -0
- data/lib/dsl/template/v1/attribute/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/attribute.rb +75 -0
- data/lib/dsl/template/v1/common_module.rb +38 -0
- data/lib/dsl/template/v1/common_module_summary.rb +42 -0
- data/lib/dsl/template/v1/component/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/component.rb +121 -0
- data/lib/dsl/template/v1/dependency.rb +63 -0
- data/lib/dsl/template/v1/module_ref.rb +62 -0
- data/lib/dsl/template/v1/node/semantic_parse.rb +62 -0
- data/lib/dsl/template/v1/node.rb +72 -0
- data/lib/dsl/template/v1/node_attribute/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/node_attribute.rb +25 -0
- data/lib/dsl/template/v1/service_instance.rb +50 -0
- data/lib/dsl/template/v1/service_module_summary.rb +37 -0
- data/lib/dsl/template/v1/workflow/semantic_parse.rb +26 -0
- data/lib/dsl/template/v1/workflow.rb +65 -0
- data/lib/dsl/template/v1.rb +43 -0
- data/lib/dsl/template.rb +110 -0
- data/lib/dsl/version.rb +6 -0
- data/lib/dsl/yaml_helper.rb +56 -0
- data/lib/dtk_dsl.rb +36 -0
- metadata +114 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module DTK::DSL
|
20
|
+
class FileGenerator
|
21
|
+
require_relative('file_generator/content_input')
|
22
|
+
require_relative('file_generator/yaml_object')
|
23
|
+
|
24
|
+
# opts can have keys
|
25
|
+
# :filter
|
26
|
+
def self.generate_yaml_object(parse_template_type, content_input, dsl_version, opts = {})
|
27
|
+
template_class = Template.template_class(parse_template_type, dsl_version)
|
28
|
+
template_class.create_for_generation(content_input, opts).generate_yaml_object
|
29
|
+
end
|
30
|
+
|
31
|
+
# opts can have keys
|
32
|
+
# :filter
|
33
|
+
def self.generate_yaml_text(parse_template_type, content_input, dsl_version, opts = {})
|
34
|
+
template_class = Template.template_class(parse_template_type, dsl_version)
|
35
|
+
template_class.create_for_generation(content_input, opts).generate_yaml_text
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/lib/dsl/file_obj.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class FileObj
|
20
|
+
# opts can have keys
|
21
|
+
# :dir_path
|
22
|
+
# :current_dir
|
23
|
+
# :content
|
24
|
+
# :file_parser - this is class
|
25
|
+
def initialize(file_type, file_path, opts = {})
|
26
|
+
@file_type = file_type
|
27
|
+
@path = file_path
|
28
|
+
@dir_path = opts[:dir_path]
|
29
|
+
@current_dir = opts[:current_dir]
|
30
|
+
@content = opts[:content]
|
31
|
+
@file_parser_class = opts[:file_parser] || FileParser
|
32
|
+
# below computed on demand
|
33
|
+
@parsed_templates = {}
|
34
|
+
@yaml_parse_hash = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_accessor :yaml_parse_hash
|
38
|
+
attr_reader :file_type
|
39
|
+
|
40
|
+
# opts can have keys:
|
41
|
+
# :dsl_version
|
42
|
+
def add_parse_content!(parse_template_type, opts = {})
|
43
|
+
parse_content(parse_template_type, opts)
|
44
|
+
self
|
45
|
+
end
|
46
|
+
def parse_content(parse_template_type, opts = {})
|
47
|
+
@parsed_templates[parse_template_type] ||= @file_parser_class.parse_content(parse_template_type, self, opts)
|
48
|
+
end
|
49
|
+
|
50
|
+
def content_or_raise_error
|
51
|
+
@content || raise(Error::Usage, error_msg_no_content)
|
52
|
+
end
|
53
|
+
def content
|
54
|
+
@content || raise(Error, 'Method should not be called if @content is nil')
|
55
|
+
end
|
56
|
+
def content?
|
57
|
+
@content
|
58
|
+
end
|
59
|
+
|
60
|
+
def raise_error_if_no_content
|
61
|
+
raise(Error::Usage, error_msg_no_content) unless @content
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def raise_error_if_no_content_flag(type)
|
66
|
+
raise(Error::Usage, error_msg_no_content_flag(type)) unless @content
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def exists?
|
71
|
+
! @content.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def path?
|
75
|
+
@path
|
76
|
+
end
|
77
|
+
|
78
|
+
def hash_content?
|
79
|
+
@file_parser_class.yaml_parse!(self) if exists?
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def error_msg_no_content
|
85
|
+
if @path
|
86
|
+
"No #{file_ref} found at '#{@path}'"
|
87
|
+
else
|
88
|
+
"Cannot find a #{file_ref} in the #{dir_ref} or ones nested under it"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def error_msg_no_content_flag(type)
|
93
|
+
type = type.to_s
|
94
|
+
type = type.slice!(0..(type.index('_')-1))
|
95
|
+
if @path
|
96
|
+
"No #{file_ref} found at '#{@path}'"
|
97
|
+
else
|
98
|
+
"Cannot find a #{type} #{file_ref} in the #{dir_ref}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def file_ref
|
103
|
+
(@file_type && @file_type.print_name) || 'DSL file'
|
104
|
+
end
|
105
|
+
|
106
|
+
def dir_ref
|
107
|
+
if @dir_path
|
108
|
+
"specified directory '#{@dir_path}'"
|
109
|
+
elsif @current_dir
|
110
|
+
"current directory '#{@current_dir}'"
|
111
|
+
else
|
112
|
+
'directory'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class FileParser
|
20
|
+
class Input
|
21
|
+
class Array < InputOutputCommon::Array
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class FileParser
|
20
|
+
class Input
|
21
|
+
class Hash < InputOutputCommon::Hash
|
22
|
+
def [](index)
|
23
|
+
super(internal_key_form(index))
|
24
|
+
end
|
25
|
+
|
26
|
+
def only_has_keys?(*only_has_keys)
|
27
|
+
(keys - only_has_keys.map{ |k| internal_key_form(k) }).empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def internal_key_form(key)
|
33
|
+
key.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class FileParser
|
20
|
+
class Input < InputOutputCommon
|
21
|
+
require_relative('input/hash')
|
22
|
+
require_relative('input/array')
|
23
|
+
|
24
|
+
def self.create(raw_input)
|
25
|
+
create_aux(obj_type(raw_input), raw_input)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class FileParser
|
20
|
+
class Output < InputOutputCommon::Canonical
|
21
|
+
extend InputOutputCommon::OutputClassMixin
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'dtk_common_core'
|
20
|
+
|
21
|
+
module DTK::DSL
|
22
|
+
class FileParser
|
23
|
+
require_relative('file_parser/input')
|
24
|
+
require_relative('file_parser/output')
|
25
|
+
|
26
|
+
# opts can have keys:
|
27
|
+
# :dsl_version
|
28
|
+
def self.parse_content(parse_template_type, file_obj, opts = {})
|
29
|
+
ret = Output.create(:output_type => :hash)
|
30
|
+
return ret unless file_obj.content?
|
31
|
+
|
32
|
+
input_hash = yaml_parse!(file_obj)
|
33
|
+
dsl_version = opts[:dsl_version] || dsl_version__raise_error_if_illegal(input_hash, file_obj)
|
34
|
+
|
35
|
+
# parsing with respect to the parse_template_type
|
36
|
+
template_class = Template.template_class(parse_template_type, dsl_version)
|
37
|
+
template_class.create_for_parsing(input_hash, :file_obj => file_obj).parse
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.yaml_parse!(file_obj)
|
41
|
+
if file_obj.respond_to?(:yaml_parse_hash)
|
42
|
+
if ret = file_obj.yaml_parse_hash
|
43
|
+
ret
|
44
|
+
else
|
45
|
+
file_obj.yaml_parse_hash = YamlHelper.parse(file_obj)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
YamlHelper.parse(file_obj)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.file_ref_in_error(file_obj)
|
53
|
+
(file_obj && file_obj.path?) ? " in file #{file_obj.path?}" : ''
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
DSL_VERSION_KEY = 'dsl_version'
|
59
|
+
def self.dsl_version__raise_error_if_illegal(input_hash, file_obj)
|
60
|
+
if dsl_version = input_hash[DSL_VERSION_KEY]
|
61
|
+
unless DSLVersion.legal?(dsl_version)
|
62
|
+
raise Error::Usage, "Illegal DSL version '#{dsl_version}'#{file_ref_in_error(file_obj)}"
|
63
|
+
end
|
64
|
+
DSLVersion.new(dsl_version)
|
65
|
+
else
|
66
|
+
DSLVersion.default
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module DTK::DSL
|
20
|
+
# This has specific file type meta info
|
21
|
+
class FileType
|
22
|
+
Types =
|
23
|
+
[
|
24
|
+
{
|
25
|
+
:type => :common_module,
|
26
|
+
:regexp => "/dtk\.module\.(yml|yaml)/",
|
27
|
+
:canonical_path => 'dtk.module.yaml',
|
28
|
+
:backup_path => 'dtk.module.bak.yaml',
|
29
|
+
:print_name => 'module DSL file'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
:type => :service_instance,
|
33
|
+
:regexp => "/dtk\.service\.(yml|yaml)/",
|
34
|
+
:canonical_path => 'dtk.service.yaml',
|
35
|
+
:backup_path => 'dtk.service.bak.yaml',
|
36
|
+
:print_name => 'service DSL file'
|
37
|
+
}
|
38
|
+
]
|
39
|
+
# regexps purposely do not have ^ or $ so calling function can insert these depending on context
|
40
|
+
|
41
|
+
Types.each do |type_info|
|
42
|
+
# convert to camel case
|
43
|
+
class_name = type_info[:type].to_s.gsub(/(?<=_|^)(\w)/){$1.upcase}.gsub(/(?:_)(\w)/,'\1')
|
44
|
+
class_eval("
|
45
|
+
class #{class_name} < self
|
46
|
+
def self.type
|
47
|
+
:#{type_info[:type]}
|
48
|
+
end
|
49
|
+
def self.print_name
|
50
|
+
'#{type_info[:print_name]}'
|
51
|
+
end
|
52
|
+
def self.canonical_path
|
53
|
+
'#{type_info[:canonical_path]}'
|
54
|
+
end
|
55
|
+
def self.backup_path
|
56
|
+
'#{type_info[:backup_path]}'
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.regexp
|
62
|
+
#{type_info[:regexp]}
|
63
|
+
end
|
64
|
+
end")
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.create_path_info
|
68
|
+
DirectoryParser::PathInfo.new(regexp)
|
69
|
+
end
|
70
|
+
|
71
|
+
# opts can have keys:
|
72
|
+
# :exact - Booelan (default: false) - meaning regexp completely matches file_path
|
73
|
+
def self.matches?(file_path, opts = {})
|
74
|
+
DirectoryParser::PathInfo.matches?(file_path, regexp, opts)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class InputOutputCommon
|
20
|
+
class Array < ::Array
|
21
|
+
def initialize(parent_class, array = nil)
|
22
|
+
array.each { |el| self << reify(parent_class, el) } if array
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def reify(parent_class, obj)
|
28
|
+
if obj.kind_of?(self.class)
|
29
|
+
obj
|
30
|
+
elsif obj.kind_of?(::Array)
|
31
|
+
inject(self.class.new(parent_class)) { |a, el| a << reify(parent_class, el) }
|
32
|
+
elsif obj.kind_of?(::Hash)
|
33
|
+
parent_class::Hash.new(parent_class, obj)
|
34
|
+
else
|
35
|
+
obj
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class InputOutputCommon
|
20
|
+
class Canonical
|
21
|
+
class Array < InputOutputCommon::Array
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class InputOutputCommon
|
20
|
+
class Canonical
|
21
|
+
class Hash < InputOutputCommon::Hash
|
22
|
+
def initialize(*args)
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def set(output_key, val)
|
27
|
+
self[canonical_key_form_from_output_key(output_key)] = val
|
28
|
+
end
|
29
|
+
|
30
|
+
def set?(output_key, val)
|
31
|
+
set(output_key, val) unless val.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
# value at index output_key
|
35
|
+
def val(output_key)
|
36
|
+
ret = nil
|
37
|
+
possible_key_forms_from_output_key(output_key).each do |internal_index|
|
38
|
+
return self[internal_index] if has_key?(internal_index)
|
39
|
+
end
|
40
|
+
ret
|
41
|
+
end
|
42
|
+
|
43
|
+
# required that value at index is non nil
|
44
|
+
def req(output_key)
|
45
|
+
ret = val(output_key)
|
46
|
+
if ret.nil?
|
47
|
+
raise Error, "Unexpected nil value for output key '#{output_key}'"
|
48
|
+
else
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def canonical_key_form_from_output_key(output_key)
|
56
|
+
HashKey.index(output_key)
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO: after converting so that all accessed keys are in canonical_key_form
|
60
|
+
# then can have do away with this method
|
61
|
+
def possible_key_forms_from_output_key(output_key)
|
62
|
+
key = canonical_key_form_from_output_key(output_key)
|
63
|
+
[key.to_s, key.to_sym]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class InputOutputCommon::Canonical
|
20
|
+
module HashKey
|
21
|
+
# Top level for common module
|
22
|
+
DSLVersion = :dsl_version
|
23
|
+
Assemblies = :assemblies
|
24
|
+
DependentModules = :dependent_modules
|
25
|
+
ModuleRef = :module
|
26
|
+
|
27
|
+
# Top level for Service Instance
|
28
|
+
Assembly = :asssembly
|
29
|
+
|
30
|
+
# Used in assembly
|
31
|
+
Components = :components
|
32
|
+
Workflows = :workflows
|
33
|
+
|
34
|
+
# Used at multiple levels
|
35
|
+
Name = :name
|
36
|
+
Description = :description
|
37
|
+
Namespace = :namespace
|
38
|
+
ModuleName = :module_name
|
39
|
+
ModuleVersion = :version
|
40
|
+
Attributes = :attributes
|
41
|
+
Value = :value
|
42
|
+
Nodes = :nodes
|
43
|
+
|
44
|
+
def self.index(output_key)
|
45
|
+
begin
|
46
|
+
const_get(output_key.to_s)
|
47
|
+
rescue
|
48
|
+
raise Error, "Illegal output hash key '#{output_key}'"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
3
|
+
#
|
4
|
+
# This file is part of the dtk project.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module DTK::DSL
|
19
|
+
class InputOutputCommon
|
20
|
+
# Canonical form that during parsing is form passed to client or server
|
21
|
+
# for generation, this is form that client or server writes to which then leads to generation
|
22
|
+
class Canonical < self
|
23
|
+
require_relative('canonical/hash_key')
|
24
|
+
require_relative('canonical/hash')
|
25
|
+
require_relative('canonical/array')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|