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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.byebug_history +70 -0
  3. data/.gitignore +2 -0
  4. data/Gemfile +2 -0
  5. data/README.md +2 -0
  6. data/dtk-dsl.gemspec +16 -0
  7. data/lib/dsl/directory_generator.rb +27 -0
  8. data/lib/dsl/directory_parser/path_info.rb +62 -0
  9. data/lib/dsl/directory_parser.rb +33 -0
  10. data/lib/dsl/dsl_version.rb +36 -0
  11. data/lib/dsl/error/subclasses.rb +38 -0
  12. data/lib/dsl/error.rb +24 -0
  13. data/lib/dsl/file_generator/content_input/array.rb +31 -0
  14. data/lib/dsl/file_generator/content_input/hash.rb +53 -0
  15. data/lib/dsl/file_generator/content_input/mixin.rb +68 -0
  16. data/lib/dsl/file_generator/content_input/string.rb +31 -0
  17. data/lib/dsl/file_generator/content_input/tags.rb +87 -0
  18. data/lib/dsl/file_generator/content_input.rb +29 -0
  19. data/lib/dsl/file_generator/yaml_object.rb +24 -0
  20. data/lib/dsl/file_generator.rb +39 -0
  21. data/lib/dsl/file_obj.rb +119 -0
  22. data/lib/dsl/file_parser/input/array.rb +27 -0
  23. data/lib/dsl/file_parser/input/hash.rb +40 -0
  24. data/lib/dsl/file_parser/input.rb +29 -0
  25. data/lib/dsl/file_parser/output.rb +24 -0
  26. data/lib/dsl/file_parser.rb +71 -0
  27. data/lib/dsl/file_type.rb +79 -0
  28. data/lib/dsl/input_output_common/array.rb +43 -0
  29. data/lib/dsl/input_output_common/canonical/array.rb +27 -0
  30. data/lib/dsl/input_output_common/canonical/hash.rb +69 -0
  31. data/lib/dsl/input_output_common/canonical/hash_key.rb +54 -0
  32. data/lib/dsl/input_output_common/canonical.rb +28 -0
  33. data/lib/dsl/input_output_common/hash.rb +44 -0
  34. data/lib/dsl/input_output_common/output_class_mixin.rb +34 -0
  35. data/lib/dsl/input_output_common/semantic_parse/hash.rb +33 -0
  36. data/lib/dsl/input_output_common/semantic_parse/mixin.rb +44 -0
  37. data/lib/dsl/input_output_common/semantic_parse.rb +26 -0
  38. data/lib/dsl/input_output_common.rb +60 -0
  39. data/lib/dsl/qualified_key.rb +55 -0
  40. data/lib/dsl/template/constant_class_mixin.rb +91 -0
  41. data/lib/dsl/template/generation/class_mixin.rb +40 -0
  42. data/lib/dsl/template/generation/mixin.rb +134 -0
  43. data/lib/dsl/template/generation.rb +26 -0
  44. data/lib/dsl/template/loader.rb +66 -0
  45. data/lib/dsl/template/parsing/class_mixin.rb +67 -0
  46. data/lib/dsl/template/parsing/mixin.rb +214 -0
  47. data/lib/dsl/template/parsing/parent_key.rb +82 -0
  48. data/lib/dsl/template/parsing/parsing_error/subclasses.rb +62 -0
  49. data/lib/dsl/template/parsing/parsing_error.rb +52 -0
  50. data/lib/dsl/template/parsing.rb +29 -0
  51. data/lib/dsl/template/v1/assembly.rb +82 -0
  52. data/lib/dsl/template/v1/attribute/semantic_parse.rb +26 -0
  53. data/lib/dsl/template/v1/attribute.rb +75 -0
  54. data/lib/dsl/template/v1/common_module.rb +38 -0
  55. data/lib/dsl/template/v1/common_module_summary.rb +42 -0
  56. data/lib/dsl/template/v1/component/semantic_parse.rb +26 -0
  57. data/lib/dsl/template/v1/component.rb +121 -0
  58. data/lib/dsl/template/v1/dependency.rb +63 -0
  59. data/lib/dsl/template/v1/module_ref.rb +62 -0
  60. data/lib/dsl/template/v1/node/semantic_parse.rb +62 -0
  61. data/lib/dsl/template/v1/node.rb +72 -0
  62. data/lib/dsl/template/v1/node_attribute/semantic_parse.rb +26 -0
  63. data/lib/dsl/template/v1/node_attribute.rb +25 -0
  64. data/lib/dsl/template/v1/service_instance.rb +50 -0
  65. data/lib/dsl/template/v1/service_module_summary.rb +37 -0
  66. data/lib/dsl/template/v1/workflow/semantic_parse.rb +26 -0
  67. data/lib/dsl/template/v1/workflow.rb +65 -0
  68. data/lib/dsl/template/v1.rb +43 -0
  69. data/lib/dsl/template.rb +110 -0
  70. data/lib/dsl/version.rb +6 -0
  71. data/lib/dsl/yaml_helper.rb +56 -0
  72. data/lib/dtk_dsl.rb +36 -0
  73. metadata +114 -0
@@ -0,0 +1,65 @@
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
+ class DTK::DSL::Template
19
+ class V1
20
+ class Workflow < self
21
+ require_relative('workflow/semantic_parse')
22
+
23
+ module Constant
24
+ module Variations
25
+ end
26
+
27
+ extend ClassMixin::Constant
28
+ end
29
+
30
+ def parser_output_type
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
+ end
38
+ end
39
+
40
+ def parse!
41
+ merge parse_workflow(input_hash)
42
+ end
43
+
44
+ ### For generation
45
+ def self.generate_elements(workflows_content, parent)
46
+ workflows_content.inject({}) do |h, (name, workflow)|
47
+ h.merge(name => generate_element(workflow, parent))
48
+ end
49
+ end
50
+
51
+ def generate!
52
+ merge(@content)
53
+ end
54
+
55
+ private
56
+
57
+ def parse_workflow(workflow_hash)
58
+ # TODO: put in fine grain parsing of workflow_hash
59
+ workflow_hash
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+
@@ -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 Template
20
+ class V1 < self
21
+ require_relative('v1/service_module_summary')
22
+ require_relative('v1/common_module_summary')
23
+ # common_module_summary must be before common_module
24
+ require_relative('v1/common_module')
25
+ require_relative('v1/service_instance')
26
+ require_relative('v1/module_ref')
27
+ require_relative('v1/assembly')
28
+ require_relative('v1/attribute')
29
+ # attribute must go before node_attribute
30
+ require_relative('v1/node_attribute')
31
+ require_relative('v1/node')
32
+ require_relative('v1/component')
33
+ require_relative('v1/workflow')
34
+ require_relative('v1/dependency')
35
+
36
+ VERSION = 1
37
+ def template_version
38
+ VERSION
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,110 @@
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 Template
20
+ require_relative('template/constant_class_mixin')
21
+ require_relative('template/parsing')
22
+ require_relative('template/generation')
23
+ require_relative('template/loader')
24
+
25
+ include Parsing::Mixin
26
+ extend Parsing::ClassMixin
27
+ include Generation::Mixin
28
+ extend Generation::ClassMixin
29
+
30
+ # opts can have keys
31
+ # :file_obj
32
+ # :parent_key
33
+ def self.create_for_parsing(raw_input, opts = {})
34
+ new(:parsing, opts.merge(:raw_input => raw_input))
35
+ end
36
+
37
+ # Content is of type InputOutput::Canonical Array or Hash
38
+ # opts can have keys
39
+ # :filter
40
+ def self.create_for_generation(content, opts = {})
41
+ new(:generation, opts.merge(:content => content))
42
+ end
43
+
44
+ def initialize(type, opts = {})
45
+ case @type = type
46
+ when :parsing then parsing_initialize(opts)
47
+ when :generation then generation_initialize(opts)
48
+ else raise Error, "Illegal type '#{type}'"
49
+ end
50
+ end
51
+
52
+ def set(constant, val)
53
+ case @type
54
+ when :parsing then parsing_set(constant, val)
55
+ when :generation then generation_set(constant, val)
56
+ end
57
+ end
58
+
59
+ def req(key)
60
+ case @type
61
+ when :generation then generation_req(key)
62
+ else fail(Error,"Method 'req' undefined for type '#{@type}'")
63
+ end
64
+ end
65
+
66
+ def val(key)
67
+ case @type
68
+ when :generation then generation_val(key)
69
+ else fail(Error,"Method 'val' undefined for type '#{@type}'")
70
+ end
71
+ end
72
+
73
+ def set?(constant, val)
74
+ set(constant, val) unless val.nil?
75
+ end
76
+
77
+ def merge(hash)
78
+ case @type
79
+ when :parsing then parsing_merge(hash)
80
+ when :generation then generation_merge(hash)
81
+ end
82
+ end
83
+
84
+ def add(array_element)
85
+ case @type
86
+ when :parsing then parsing_add(array_element)
87
+ when :generation then generation_add(array_element)
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def self.template_class(parse_template_type, dsl_version)
94
+ Loader.template_class(parse_template_type, :dsl_version => dsl_version)
95
+ end
96
+
97
+ def template_class(parse_template_type)
98
+ self.class.template_class(parse_template_type, template_version)
99
+ end
100
+
101
+ def canonical_key(constant)
102
+ constant_class.canonical_value(constant)
103
+ end
104
+
105
+ def constant_class
106
+ self.class::Constant
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,6 @@
1
+ module DTK
2
+ module DSL
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
6
+
@@ -0,0 +1,56 @@
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
+ require 'yaml'
19
+ module DTK::DSL
20
+ module YamlHelper
21
+ # Returns hash if succsefully parse; otherwise raises error
22
+ def self.parse(file_obj)
23
+ begin
24
+ ::YAML.load(file_obj.content)
25
+ rescue Exception => e
26
+ raise Error::Usage, yaml_parsing_error_msg(e, file_obj)
27
+ end
28
+ end
29
+
30
+ def self.generate(yaml_object)
31
+ ::YAML.dump(convert_for_yaml_dump(yaml_object))
32
+ end
33
+
34
+ private
35
+
36
+ def self.yaml_parsing_error_msg(e, file_obj)
37
+ file_ref = FileParser.file_ref_in_error(file_obj)
38
+ yaml_err_msg = e.message.gsub(/\(<unknown>\): /,'').capitalize
39
+ "YAML parsing error#{file_ref}:\n#{yaml_err_msg}"
40
+ end
41
+
42
+ # this method converts embedded hash and array objects to be ::Hash and ::Array objects
43
+ # so YAML rendering does not have objects in it
44
+ def self.convert_for_yaml_dump(yaml_object)
45
+ if yaml_object.kind_of?(::Array)
46
+ ret = []
47
+ yaml_object.each { |el| ret << convert_for_yaml_dump(el) }
48
+ ret
49
+ elsif yaml_object.kind_of?(::Hash)
50
+ yaml_object.inject({}) { |h, (k, v)| h.merge(k => convert_for_yaml_dump(v)) }
51
+ else
52
+ yaml_object
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/dtk_dsl.rb ADDED
@@ -0,0 +1,36 @@
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
20
+ module DSL
21
+ require_relative('dsl/error')
22
+ require_relative('dsl/dsl_version')
23
+ require_relative('dsl/file_type')
24
+ require_relative('dsl/file_obj')
25
+ require_relative('dsl/yaml_helper')
26
+ require_relative('dsl/directory_parser')
27
+ require_relative('dsl/directory_generator')
28
+ require_relative('dsl/qualified_key')
29
+ require_relative('dsl/input_output_common')
30
+ # input_output_common must be before file_parser and file_generator
31
+ require_relative('dsl/file_parser')
32
+ require_relative('dsl/file_generator')
33
+ require_relative('dsl/template')
34
+
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtk-dsl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Reactor8
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Library for parsing DT DSL files.
14
+ email: support@reactor8.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".byebug_history"
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - README.md
23
+ - dtk-dsl.gemspec
24
+ - lib/dsl/directory_generator.rb
25
+ - lib/dsl/directory_parser.rb
26
+ - lib/dsl/directory_parser/path_info.rb
27
+ - lib/dsl/dsl_version.rb
28
+ - lib/dsl/error.rb
29
+ - lib/dsl/error/subclasses.rb
30
+ - lib/dsl/file_generator.rb
31
+ - lib/dsl/file_generator/content_input.rb
32
+ - lib/dsl/file_generator/content_input/array.rb
33
+ - lib/dsl/file_generator/content_input/hash.rb
34
+ - lib/dsl/file_generator/content_input/mixin.rb
35
+ - lib/dsl/file_generator/content_input/string.rb
36
+ - lib/dsl/file_generator/content_input/tags.rb
37
+ - lib/dsl/file_generator/yaml_object.rb
38
+ - lib/dsl/file_obj.rb
39
+ - lib/dsl/file_parser.rb
40
+ - lib/dsl/file_parser/input.rb
41
+ - lib/dsl/file_parser/input/array.rb
42
+ - lib/dsl/file_parser/input/hash.rb
43
+ - lib/dsl/file_parser/output.rb
44
+ - lib/dsl/file_type.rb
45
+ - lib/dsl/input_output_common.rb
46
+ - lib/dsl/input_output_common/array.rb
47
+ - lib/dsl/input_output_common/canonical.rb
48
+ - lib/dsl/input_output_common/canonical/array.rb
49
+ - lib/dsl/input_output_common/canonical/hash.rb
50
+ - lib/dsl/input_output_common/canonical/hash_key.rb
51
+ - lib/dsl/input_output_common/hash.rb
52
+ - lib/dsl/input_output_common/output_class_mixin.rb
53
+ - lib/dsl/input_output_common/semantic_parse.rb
54
+ - lib/dsl/input_output_common/semantic_parse/hash.rb
55
+ - lib/dsl/input_output_common/semantic_parse/mixin.rb
56
+ - lib/dsl/qualified_key.rb
57
+ - lib/dsl/template.rb
58
+ - lib/dsl/template/constant_class_mixin.rb
59
+ - lib/dsl/template/generation.rb
60
+ - lib/dsl/template/generation/class_mixin.rb
61
+ - lib/dsl/template/generation/mixin.rb
62
+ - lib/dsl/template/loader.rb
63
+ - lib/dsl/template/parsing.rb
64
+ - lib/dsl/template/parsing/class_mixin.rb
65
+ - lib/dsl/template/parsing/mixin.rb
66
+ - lib/dsl/template/parsing/parent_key.rb
67
+ - lib/dsl/template/parsing/parsing_error.rb
68
+ - lib/dsl/template/parsing/parsing_error/subclasses.rb
69
+ - lib/dsl/template/v1.rb
70
+ - lib/dsl/template/v1/assembly.rb
71
+ - lib/dsl/template/v1/attribute.rb
72
+ - lib/dsl/template/v1/attribute/semantic_parse.rb
73
+ - lib/dsl/template/v1/common_module.rb
74
+ - lib/dsl/template/v1/common_module_summary.rb
75
+ - lib/dsl/template/v1/component.rb
76
+ - lib/dsl/template/v1/component/semantic_parse.rb
77
+ - lib/dsl/template/v1/dependency.rb
78
+ - lib/dsl/template/v1/module_ref.rb
79
+ - lib/dsl/template/v1/node.rb
80
+ - lib/dsl/template/v1/node/semantic_parse.rb
81
+ - lib/dsl/template/v1/node_attribute.rb
82
+ - lib/dsl/template/v1/node_attribute/semantic_parse.rb
83
+ - lib/dsl/template/v1/service_instance.rb
84
+ - lib/dsl/template/v1/service_module_summary.rb
85
+ - lib/dsl/template/v1/workflow.rb
86
+ - lib/dsl/template/v1/workflow/semantic_parse.rb
87
+ - lib/dsl/version.rb
88
+ - lib/dsl/yaml_helper.rb
89
+ - lib/dtk_dsl.rb
90
+ homepage:
91
+ licenses:
92
+ - Apache 2.0
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.9.3
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Library for parsing DT DSL files.
114
+ test_files: []