dtk-dsl 1.0.0 → 1.0.1
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/dsl/aux.rb +31 -0
- data/lib/dsl/directory_parser.rb +3 -7
- data/lib/dsl/dsl_version.rb +1 -0
- data/lib/dsl/file_generator/content_input/mixin.rb +2 -5
- data/lib/dsl/file_generator/content_input/tag/assignment.rb +32 -0
- data/lib/dsl/file_generator/content_input/tag/simple.rb +26 -0
- data/lib/dsl/file_generator/content_input/{tags.rb → tag.rb} +61 -23
- data/lib/dsl/file_generator/content_input.rb +1 -1
- data/lib/dsl/file_generator.rb +7 -0
- data/lib/dsl/file_parser.rb +1 -0
- data/lib/dsl/file_type/match.rb +68 -0
- data/lib/dsl/file_type/matching_files.rb +57 -0
- data/lib/dsl/file_type/subclasses.rb +71 -0
- data/lib/dsl/file_type.rb +120 -51
- data/lib/dsl/input_output_common/canonical/hash.rb +7 -1
- data/lib/dsl/input_output_common/canonical/hash_key.rb +20 -1
- data/lib/dsl/qualified_key.rb +2 -0
- data/lib/dsl/template/constant_class_mixin.rb +8 -9
- data/lib/dsl/template/generation/class_mixin.rb +6 -2
- data/lib/dsl/template/generation/mixin.rb +35 -20
- data/lib/dsl/template/loader.rb +1 -1
- data/lib/dsl/template/nested_dsl_file/mixin.rb +77 -0
- data/lib/dsl/template/nested_dsl_file.rb +25 -0
- data/lib/dsl/template/parsing/class_mixin.rb +8 -9
- data/lib/dsl/template/parsing/mixin.rb +31 -8
- data/lib/dsl/template/v1/assembly.rb +13 -16
- data/lib/dsl/template/v1/common_module_summary.rb +1 -1
- data/lib/dsl/template/v1/component.rb +12 -8
- data/lib/dsl/template/v1/service_instance.rb +5 -3
- data/lib/dsl/template/v1/workflow.rb +108 -38
- data/lib/dsl/template/v1.rb +4 -0
- data/lib/dsl/template.rb +3 -0
- data/lib/dsl/version.rb +1 -1
- data/lib/dtk_dsl.rb +1 -0
- metadata +11 -4
- data/lib/dsl/directory_parser/path_info.rb +0 -62
@@ -15,50 +15,120 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
|
19
|
-
class
|
20
|
-
class
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
module DTK::DSL
|
19
|
+
class Template
|
20
|
+
class V1
|
21
|
+
class Workflow < self
|
22
|
+
# TODO: do we want workflow/semantic_parse
|
23
|
+
require_relative('workflow/semantic_parse')
|
24
|
+
|
25
|
+
module Constant
|
26
|
+
module Variations
|
27
|
+
end
|
28
|
+
|
29
|
+
extend ClassMixin::Constant
|
30
|
+
Import = 'import'
|
31
|
+
Name = 'name'
|
32
|
+
SubtaskOrder = 'subtask_order'
|
33
|
+
Subtasks = 'subtasks'
|
34
|
+
Flatten = 'flatten'
|
25
35
|
end
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
:hash
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.parse_elements(input_hash, parent_info)
|
35
|
-
input_hash.inject(file_parser_output_hash) do |h, (name, workflow)|
|
36
|
-
h.merge(name => parse_element(workflow, parent_info, :index => name))
|
37
|
+
### For parsing
|
38
|
+
|
39
|
+
def parser_output_type
|
40
|
+
:hash
|
37
41
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
|
43
|
+
def self.parse_elements(input_hash, parent_info)
|
44
|
+
input_hash.inject(file_parser_output_hash) do |h, (name, workflow)|
|
45
|
+
h.merge(name => parse_element(workflow, parent_info, :index => name))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse!
|
50
|
+
remove_processed_keys_from_input_hash! do
|
51
|
+
set? :Import, input_key_value?(:Import)
|
52
|
+
set? :Flatten, input_key_value?(:Flatten)
|
53
|
+
set? :Name, input_key_value?(:Name)
|
54
|
+
set? :SubtaskOrder, input_key_value?(:SubtaskOrder)
|
55
|
+
set? :Subtasks, parse_subtasks?
|
56
|
+
end
|
57
|
+
# handle keys not processed
|
58
|
+
merge change_strings_to_symbols(input_hash) unless input_hash.empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
### For generation
|
62
|
+
def self.generate_elements(workflows_content, parent)
|
63
|
+
workflows_content.inject({}) do |h, (name, workflow)|
|
64
|
+
h.merge(name => generate_element(workflow, parent))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def generate!
|
69
|
+
set? :Name, val(:Name)
|
70
|
+
set? :SubtaskOrder, val(:SubtaskOrder)
|
71
|
+
if subtasks = val(:Subtasks)
|
72
|
+
generated_subtasks = subtasks.map do |subtask|
|
73
|
+
generated_subtask = generate_subtask(subtask)
|
74
|
+
generated_subtask.empty? ? nil : generated_subtask
|
75
|
+
end.compact
|
76
|
+
set :Subtasks, generated_subtasks unless generated_subtasks.empty?
|
77
|
+
end
|
78
|
+
merge(uninterpreted_keys)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def parse_subtasks?
|
84
|
+
if subtasks = input_key_value?(:Subtasks)
|
85
|
+
ret = file_parser_output_array
|
86
|
+
subtasks.each_with_index do |subtask, i|
|
87
|
+
# TODO: should parent_info instead be Parsing::ParentInfo.new(self, :subtasks)
|
88
|
+
parent_info = Parsing::ParentInfo.new(self, :workflow)
|
89
|
+
ret << self.class.parse_element(subtask, parent_info, :index => i)
|
90
|
+
end
|
91
|
+
ret
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def generate_subtask(subtask)
|
96
|
+
self.class.create_for_generation(subtask, :top => @top, :filter => @filter).generate_yaml_object
|
48
97
|
end
|
49
|
-
end
|
50
98
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
99
|
+
module Hashkey
|
100
|
+
include InputOutputCommon::Canonical::HashKey
|
101
|
+
end
|
102
|
+
INTERPRETED_KEYS = [Hashkey::Name, Hashkey::SubtaskOrder, Hashkey::Subtasks, Hashkey::Flatten, Hashkey::Import, Hashkey::HiddenImportStatement]
|
103
|
+
def uninterpreted_keys
|
104
|
+
(@content.keys - INTERPRETED_KEYS).inject({}) do |h, k|
|
105
|
+
h.merge(k.to_s => change_symbols_to_strings(@content[k]))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def change_symbols_to_strings(obj)
|
110
|
+
if obj.kind_of?(::Hash)
|
111
|
+
obj.inject({}) { |h, (k, v)| h.merge(k.to_s => change_symbols_to_strings(v)) }
|
112
|
+
elsif obj.kind_of?(::Array)
|
113
|
+
obj.map { |el| change_symbols_to_strings(el) }
|
114
|
+
elsif obj.kind_of?(::Symbol)
|
115
|
+
obj.to_s
|
116
|
+
else
|
117
|
+
obj
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def change_strings_to_symbols(obj)
|
122
|
+
if obj.kind_of?(::Hash)
|
123
|
+
obj.inject({}) { |h, (k, v)| h.merge(k.to_sym => change_strings_to_symbols(v)) }
|
124
|
+
elsif obj.kind_of?(::Array)
|
125
|
+
obj.map { |el| change_strings_to_symbols(el) }
|
126
|
+
else
|
127
|
+
obj
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
60
131
|
end
|
61
|
-
|
62
132
|
end
|
63
133
|
end
|
64
134
|
end
|
data/lib/dsl/template/v1.rb
CHANGED
data/lib/dsl/template.rb
CHANGED
@@ -20,12 +20,15 @@ module DTK::DSL
|
|
20
20
|
require_relative('template/constant_class_mixin')
|
21
21
|
require_relative('template/parsing')
|
22
22
|
require_relative('template/generation')
|
23
|
+
require_relative('template/nested_dsl_file')
|
23
24
|
require_relative('template/loader')
|
24
25
|
|
25
26
|
include Parsing::Mixin
|
26
27
|
extend Parsing::ClassMixin
|
27
28
|
include Generation::Mixin
|
28
29
|
extend Generation::ClassMixin
|
30
|
+
include NestedDSLFile::Mixin
|
31
|
+
|
29
32
|
|
30
33
|
# opts can have keys
|
31
34
|
# :file_obj
|
data/lib/dsl/version.rb
CHANGED
data/lib/dtk_dsl.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtk-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reactor8
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Library for parsing DT DSL files.
|
14
14
|
email: support@reactor8.com
|
@@ -21,9 +21,9 @@ files:
|
|
21
21
|
- Gemfile
|
22
22
|
- README.md
|
23
23
|
- dtk-dsl.gemspec
|
24
|
+
- lib/dsl/aux.rb
|
24
25
|
- lib/dsl/directory_generator.rb
|
25
26
|
- lib/dsl/directory_parser.rb
|
26
|
-
- lib/dsl/directory_parser/path_info.rb
|
27
27
|
- lib/dsl/dsl_version.rb
|
28
28
|
- lib/dsl/error.rb
|
29
29
|
- lib/dsl/error/subclasses.rb
|
@@ -33,7 +33,9 @@ files:
|
|
33
33
|
- lib/dsl/file_generator/content_input/hash.rb
|
34
34
|
- lib/dsl/file_generator/content_input/mixin.rb
|
35
35
|
- lib/dsl/file_generator/content_input/string.rb
|
36
|
-
- lib/dsl/file_generator/content_input/
|
36
|
+
- lib/dsl/file_generator/content_input/tag.rb
|
37
|
+
- lib/dsl/file_generator/content_input/tag/assignment.rb
|
38
|
+
- lib/dsl/file_generator/content_input/tag/simple.rb
|
37
39
|
- lib/dsl/file_generator/yaml_object.rb
|
38
40
|
- lib/dsl/file_obj.rb
|
39
41
|
- lib/dsl/file_parser.rb
|
@@ -42,6 +44,9 @@ files:
|
|
42
44
|
- lib/dsl/file_parser/input/hash.rb
|
43
45
|
- lib/dsl/file_parser/output.rb
|
44
46
|
- lib/dsl/file_type.rb
|
47
|
+
- lib/dsl/file_type/match.rb
|
48
|
+
- lib/dsl/file_type/matching_files.rb
|
49
|
+
- lib/dsl/file_type/subclasses.rb
|
45
50
|
- lib/dsl/input_output_common.rb
|
46
51
|
- lib/dsl/input_output_common/array.rb
|
47
52
|
- lib/dsl/input_output_common/canonical.rb
|
@@ -60,6 +65,8 @@ files:
|
|
60
65
|
- lib/dsl/template/generation/class_mixin.rb
|
61
66
|
- lib/dsl/template/generation/mixin.rb
|
62
67
|
- lib/dsl/template/loader.rb
|
68
|
+
- lib/dsl/template/nested_dsl_file.rb
|
69
|
+
- lib/dsl/template/nested_dsl_file/mixin.rb
|
63
70
|
- lib/dsl/template/parsing.rb
|
64
71
|
- lib/dsl/template/parsing/class_mixin.rb
|
65
72
|
- lib/dsl/template/parsing/mixin.rb
|
@@ -1,62 +0,0 @@
|
|
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 DirectoryParser
|
21
|
-
class PathInfo
|
22
|
-
attr_reader :regexp, :depth, :base_dir
|
23
|
-
# opts can have keys
|
24
|
-
# :depth - used for pruning when a git directory
|
25
|
-
def initialize(regexp_or_string, opts = {})
|
26
|
-
@regexp = ret_regexp(regexp_or_string)
|
27
|
-
@depth = opts[:depth]
|
28
|
-
@base_dir = opts[:base_dir]
|
29
|
-
end
|
30
|
-
|
31
|
-
# opts can have keys:
|
32
|
-
# :exact - Booelan (default: false) - meaning regexp completely matches file_path
|
33
|
-
def matches?(file_path, opts = {})
|
34
|
-
self.class.matches?(file_path, @regexp, opts)
|
35
|
-
end
|
36
|
-
def self.matches?(file_path, regexp, opts = {})
|
37
|
-
if opts[:exact]
|
38
|
-
file_path =~ Regexp.new("^#{regexp.source}$")
|
39
|
-
else
|
40
|
-
# extra check to see if regexp is just for file part or has '/' seperators
|
41
|
-
if '/' =~ regexp
|
42
|
-
file_path.split('/').last =~ Regexp.new("^#{regexp.source}$")
|
43
|
-
else
|
44
|
-
file_path =~ Regexp.new("#{regexp.source}$")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def ret_regexp(regexp_or_string)
|
52
|
-
if regexp_or_string.kind_of?(String)
|
53
|
-
Regexp.new(regexp_or_string)
|
54
|
-
elsif regexp_or_string.kind_of?(Regexp)
|
55
|
-
regexp_or_string
|
56
|
-
else
|
57
|
-
raise Error, "Unexpected class '#{regexp_or_string.class}'"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|