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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6850c2038d1af4481513a9d06fdf9391d589241
4
+ data.tar.gz: 8ff25444f0f40e76ebcdab8672ead6a2d71e06b8
5
+ SHA512:
6
+ metadata.gz: aa6414e6bc8f983c86f4416ce750c4d2754311e48bd6beabe22eab121e013a8326b1d487237f4c1baed66f46a00487a2c2a20aed3b7ad9e982a8336628c15b77
7
+ data.tar.gz: c843fe596c4c9d9ecd5f53d06eb5c612c374b736d1af3ddf2d76094a83c3821dcb68e439580ef22d8cfd8a34ab38d7db465e81f3b21a6d9e7c678d1fa804af5a
data/.byebug_history ADDED
@@ -0,0 +1,70 @@
1
+ c
2
+ s
3
+ @valid_tags
4
+ s
5
+ c
6
+ b 70
7
+ c
8
+ quit
9
+ tag_split.size
10
+ tag_split.split.size
11
+ tag_split.split >= tag_type_split.size
12
+ n
13
+ split(tag)
14
+ split(tag_type)
15
+ pp [tag_type, tag]
16
+ s
17
+ n
18
+ b 43
19
+ compute_valid_tags
20
+ s
21
+ c
22
+ b /tmp/t.rb:17
23
+ c
24
+ quit
25
+ tag_split
26
+ n
27
+ split(tag)
28
+ c
29
+ b 49
30
+ c
31
+ quit
32
+ exit
33
+ t.to_s.split(DELIMITER).map(&:to_sym)
34
+ t.to_s.split(DELIMITER).map(to_sym)
35
+ t.to_s.split(DELIMITER).map(&to_sym)
36
+ t.to_s.split(DELIMITER).map { |x| x.to_sym}
37
+ t.to_s.split(DELIMITER).map(&to_sym)
38
+ t.to_s.split(DELIMITER)
39
+ t
40
+ s
41
+ pp tag
42
+ c
43
+ b 49
44
+ c
45
+ s
46
+ base_dsl_file_obj.file_type
47
+ base_dsl_file_obj.path?
48
+ n
49
+ base_dsl_file_obj.path?
50
+ s
51
+ c
52
+ b /home/cli/dtk-cli/lib/cli/context.rb:40
53
+ c
54
+ pp base_dsl_file_obj
55
+ base_dsl_file_obj
56
+ base_dsl_file_obj.path?
57
+ s
58
+ n
59
+ s
60
+ c
61
+ b /home/cli/dtk-cli/lib/cli/directory_parser/file_system.rb:38
62
+ c
63
+ quit
64
+ s
65
+ c
66
+ b /home/cli/.gem/ruby/2.0/gems/dtk-dsl-0.0.1/lib/dtk_dsl.rb:20
67
+ n
68
+ s
69
+ n
70
+ s
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ sftp-config*.json
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # dtk-client2
2
+ DTK client
data/dtk-dsl.gemspec ADDED
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../lib/dsl/version', __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'dtk-dsl'
5
+ spec.version = DTK::DSL::VERSION
6
+ spec.author = 'Reactor8'
7
+ spec.email = 'support@reactor8.com'
8
+ spec.description = %q{Library for parsing DT DSL files.}
9
+ spec.summary = %q{Library for parsing DT DSL files.}
10
+ spec.license = 'Apache 2.0'
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
13
+
14
+ spec.require_paths = ['lib']
15
+ spec.files = `git ls-files`.split("\n")
16
+ end
@@ -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
+
19
+ module DTK::DSL
20
+ # Abstract class; application that uses this library must provide a concrete class that inherits from this
21
+ class DirectoryGenerator
22
+ # Adds or modifies file; returns true if new file or any change
23
+ def self.add_file?(file_type, file_content, opts = {})
24
+ raise Error::NoMethodForConcreteClass.new(self.class)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,62 @@
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
@@ -0,0 +1,33 @@
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
+ # Abstract class; application that uses this library must provide a concrete class that inherits from this
21
+ class DirectoryParser
22
+ require_relative('directory_parser/path_info')
23
+ # file_types - a single or array of FileObj objects
24
+ # opts can have keys
25
+ # :file_path - string
26
+ # :dir_path - string
27
+ # Returns FileObj that matches a file_typeo bject that matches a file_type in file_types
28
+ # or returns nil if no match found
29
+ def self.matching_file_obj?(file_types, opts = {})
30
+ raise Error::NoMethodForConcreteClass.new(self.class)
31
+ end
32
+ end
33
+ end
@@ -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::DSL
20
+ # This refers to semnatic dsl version
21
+ class DSLVersion < ::String
22
+ DSL_VERSIONS = ['1.0.0']
23
+
24
+ def self.legal?(str)
25
+ DSL_VERSIONS.include?(str)
26
+ end
27
+
28
+ def self.lataset
29
+ DSL_VERSIONS.last
30
+ end
31
+
32
+ def self.default
33
+ lataset
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
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
19
+ module DSL
20
+ class Error
21
+ class Usage < GlobalForDSL::ErrorUsage
22
+ end
23
+
24
+ class NoMethodForConcreteClass < self
25
+ def initialize(klass)
26
+ method_string = caller[1]
27
+ method_ref =
28
+ if method_string =~ /`(.+)'$/
29
+ method = $1
30
+ " '#{method}'"
31
+ end
32
+ super("No method#{method_ref} for concrete class #{klass}")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
data/lib/dsl/error.rb ADDED
@@ -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
19
+ module DSL
20
+ class Error < GlobalForDSL::Error
21
+ require_relative('error/subclasses')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
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 FileGenerator
20
+ class ContentInput
21
+ class Array < InputOutputCommon::Canonical::Array
22
+ include Mixin
23
+
24
+ def initialize(*args)
25
+ super
26
+ initialize_tags_and_id_handle!
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,53 @@
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 FileGenerator
20
+ class ContentInput
21
+ class Hash < InputOutputCommon::Canonical::Hash
22
+ include Mixin
23
+
24
+ def initialize(*args)
25
+ super
26
+ initialize_tags_and_id_handle!
27
+ end
28
+
29
+ # opts can have keys
30
+ # :tags
31
+ # :tag
32
+ def set(output_key, val, opts = {})
33
+ ret = super(output_key, val)
34
+ tags = opts[:tag] || opts[:tags]
35
+ add_tags_to_obj?(ret, tags) unless tags.nil?
36
+ ret
37
+ end
38
+
39
+ # opts can have keys
40
+ # :tag - tag to filter on
41
+ def val(output_key, opts = {})
42
+ ret = super(output_key)
43
+ if tag = opts[:tag]
44
+ ret = nil unless obj_has_tag?(ret, tag)
45
+ end
46
+ ret
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,68 @@
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 FileGenerator::ContentInput
20
+ # Mixin for tags and id_handle object attributes
21
+ module Mixin
22
+ attr_reader :tags
23
+ def initialize_tags_and_id_handle!
24
+ @tags = []
25
+ @id_handle = nil
26
+ end
27
+
28
+ def set_id_handle(model_object)
29
+ @id_handle = model_object.id_handle
30
+ end
31
+
32
+ def id_handle
33
+ @id_handle || raise(Error,"@id_handle is not set")
34
+ end
35
+
36
+ def add_tags!(new_tags)
37
+ Tags.raise_error_if_invalid(new_tags)
38
+ new_tags = [new_tags] unless new_tags.kind_of?(::Array)
39
+ @tags += new_tags
40
+ @tags.uniq!
41
+ self
42
+ end
43
+
44
+ def add_tags?(new_tags)
45
+ add_tags!(new_tags) unless new_tags.nil? or new_tags.empty?
46
+ end
47
+
48
+ def matches_tag_type?(tag_type)
49
+ !! @tags.find { |tag| Tags.matches_tag_type?(tag_type, tag) }
50
+ end
51
+
52
+ def add_tags_to_obj?(obj, new_tags)
53
+ obj.add_tags!(new_tags) if obj.respond_to?(:add_tags!)
54
+ obj
55
+ end
56
+
57
+ def obj_has_tag_type?(obj, tag_type)
58
+ if obj.respond_to?(:matches_tag_type?)
59
+ obj.matches_tag_type?(tag_type)
60
+ else
61
+ # vacuously succeeds
62
+ true
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,31 @@
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 FileGenerator
20
+ class ContentInput
21
+ class String < ::String
22
+ include Mixin
23
+
24
+ def initialize(*args)
25
+ super
26
+ initialize_tags_and_id_handle!
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,87 @@
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 FileGenerator::ContentInput
20
+ module Tags
21
+ #####
22
+ # In this module a 'tag_type' subsumes a tag and consitutes an element in BASE_LEVEL_TAGS or one its prefixes
23
+ #
24
+ DELIMITER = '__'
25
+ BASE_LEVEL_TAGS =
26
+ [:desired__asserted,
27
+ :desired__derived__default,
28
+ :desired__derived__propagated,
29
+ :actual,
30
+ :hidden
31
+ ]
32
+
33
+ def self.matches_tag_type?(tag_type, tag)
34
+ tag_type_split = split(tag_type)
35
+ tag_split = split(tag)
36
+ if tag_split.size >= tag_type_split.size
37
+ tag_type_split.each_with_index do |tag_type_part, i|
38
+ return nil unless tag_type_part == tag_split[i]
39
+ end
40
+ true
41
+ end
42
+ end
43
+
44
+ def self.valid?(tag_type)
45
+ valid_tag_types.include?(tag_type)
46
+ end
47
+
48
+ def self.raise_error_if_invalid(tag_types)
49
+ tag_types = [tag_types] unless tag_types.kind_of?(::Array)
50
+ bad_tag_types = tag_types.select { |tag| !valid?(tag)}
51
+ unless bad_tag_types.empty?
52
+ err_msg = bad_tag_types.size == 1 ? "Invalid tag '#{bad_tag_types.first}'" : "Invalid tag_types: #{bad_tag_types.join(', ')}"
53
+ raise Error, err_msg
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def self.valid_tag_types
60
+ @valid_tag_tag_types ||= compute_valid_tag_types
61
+ end
62
+
63
+ # Iterates over BASE_LEVEL_TAGS and puts in prefixes
64
+ def self.compute_valid_tag_types
65
+ ret = []
66
+ BASE_LEVEL_TAGS.each do |tag|
67
+ tag_split = split(tag)
68
+ until tag_split.empty?
69
+ ret << join(tag_split)
70
+ tag_split.pop
71
+ end
72
+ end
73
+ ret.uniq
74
+ end
75
+
76
+ def self.split(t)
77
+ t.to_s.split(DELIMITER).map(&:to_sym)
78
+ end
79
+
80
+ def self.join(t_split)
81
+ t_split.map(&:to_s).join(DELIMITER).to_sym
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+
@@ -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 FileGenerator
20
+ class ContentInput < InputOutputCommon::Canonical
21
+ require_relative('content_input/tags')
22
+ require_relative('content_input/mixin')
23
+ # mixin must go before the files below
24
+ require_relative('content_input/hash')
25
+ require_relative('content_input/array')
26
+ require_relative('content_input/string')
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 FileGenerator
20
+ class YamlObject < InputOutputCommon
21
+ extend InputOutputCommon::OutputClassMixin
22
+ end
23
+ end
24
+ end