cloud-templates 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +1 -0
  4. data/Rakefile +1 -1
  5. data/bin/cloud-templates-runner.rb +5 -0
  6. data/cloud-templates.gemspec +9 -4
  7. data/examples/lib/user_directory.rb +0 -10
  8. data/examples/lib/user_directory/artifacts.rb +8 -0
  9. data/examples/lib/user_directory/artifacts/catalogized.rb +8 -7
  10. data/examples/lib/user_directory/artifacts/group.rb +27 -30
  11. data/examples/lib/user_directory/artifacts/ided.rb +8 -7
  12. data/examples/lib/user_directory/artifacts/organization.rb +10 -11
  13. data/examples/lib/user_directory/artifacts/pathed.rb +17 -17
  14. data/examples/lib/user_directory/artifacts/person.rb +20 -15
  15. data/examples/lib/user_directory/artifacts/team.rb +26 -21
  16. data/examples/lib/user_directory/artifacts/unit.rb +15 -17
  17. data/examples/lib/user_directory/artifacts/user.rb +26 -23
  18. data/examples/lib/user_directory/render.rb +8 -0
  19. data/examples/lib/user_directory/render/etc.rb +2 -0
  20. data/examples/lib/user_directory/render/etc/artifact_view.rb +2 -2
  21. data/examples/lib/user_directory/render/etc/composite_view.rb +1 -2
  22. data/examples/lib/user_directory/render/etc/group_view.rb +3 -3
  23. data/examples/lib/user_directory/render/etc/person_view.rb +2 -2
  24. data/examples/lib/user_directory/render/etc/registry.rb +4 -6
  25. data/examples/lib/user_directory/render/etc/user_view.rb +2 -3
  26. data/examples/lib/user_directory/render/ldap.rb +2 -0
  27. data/examples/lib/user_directory/render/ldap/artifact_view.rb +3 -4
  28. data/examples/lib/user_directory/render/ldap/composite_view.rb +3 -4
  29. data/examples/lib/user_directory/render/ldap/group_view.rb +3 -4
  30. data/examples/lib/user_directory/render/ldap/organization_view.rb +3 -4
  31. data/examples/lib/user_directory/render/ldap/person_view.rb +3 -4
  32. data/examples/lib/user_directory/render/ldap/registry.rb +3 -4
  33. data/examples/lib/user_directory/render/ldap/unit_view.rb +3 -4
  34. data/examples/lib/user_directory/render/ldap/user_view.rb +3 -4
  35. data/examples/lib/user_directory/utils.rb +1 -1
  36. data/examples/spec/user_directory_spec.rb +24 -25
  37. data/lib/aws/templates.rb +0 -8
  38. data/lib/aws/templates/artifact.rb +20 -12
  39. data/lib/aws/templates/cli.rb +14 -0
  40. data/lib/aws/templates/cli/formatter.rb +21 -0
  41. data/lib/aws/templates/cli/formatter/json.rb +20 -0
  42. data/lib/aws/templates/cli/interface.rb +92 -0
  43. data/lib/aws/templates/composite.rb +6 -9
  44. data/lib/aws/templates/exception.rb +8 -0
  45. data/lib/aws/templates/exception/nested_parameter_exception.rb +19 -0
  46. data/lib/aws/templates/exception/option_error.rb +14 -0
  47. data/lib/aws/templates/exception/option_scalar_on_the_way.rb +26 -0
  48. data/lib/aws/templates/exception/option_should_be_recursive.rb +20 -0
  49. data/lib/aws/templates/exception/option_value_deleted.rb +22 -0
  50. data/lib/aws/templates/exception/parameter_already_exist.rb +26 -0
  51. data/lib/aws/templates/exception/parameter_exception.rb +26 -0
  52. data/lib/aws/templates/exception/parameter_getter_is_not_defined.rb +23 -0
  53. data/lib/aws/templates/exception/parameter_method_name_conflict.rb +26 -0
  54. data/lib/aws/templates/exception/parameter_specification_is_invalid.rb +30 -0
  55. data/lib/aws/templates/exception/parameter_value_invalid.rb +37 -0
  56. data/lib/aws/templates/exception/parametrized_dsl_error.rb +14 -0
  57. data/lib/aws/templates/exception/view_not_found.rb +26 -0
  58. data/lib/aws/templates/help.rb +43 -0
  59. data/lib/aws/templates/help/aggregate.rb +74 -0
  60. data/lib/aws/templates/help/dsl.rb +30 -0
  61. data/lib/aws/templates/help/provider.rb +15 -0
  62. data/lib/aws/templates/help/rdoc.rb +105 -0
  63. data/lib/aws/templates/help/rdoc/artifact.rb +50 -0
  64. data/lib/aws/templates/help/rdoc/composite.rb +20 -0
  65. data/lib/aws/templates/help/rdoc/contextualized.rb +12 -0
  66. data/lib/aws/templates/help/rdoc/contextualized/filter.rb +19 -0
  67. data/lib/aws/templates/help/rdoc/contextualized/filters.rb +14 -0
  68. data/lib/aws/templates/help/rdoc/contextualized/filters/add.rb +21 -0
  69. data/lib/aws/templates/help/rdoc/contextualized/filters/chain.rb +33 -0
  70. data/lib/aws/templates/help/rdoc/contextualized/filters/copy.rb +23 -0
  71. data/lib/aws/templates/help/rdoc/contextualized/filters/identity.rb +23 -0
  72. data/lib/aws/templates/help/rdoc/contextualized/filters/override.rb +29 -0
  73. data/lib/aws/templates/help/rdoc/contextualized/filters/proxy.rb +28 -0
  74. data/lib/aws/templates/help/rdoc/contextualized/filters/recursive_schema_filter.rb +28 -0
  75. data/lib/aws/templates/help/rdoc/contextualized/filters/remove.rb +21 -0
  76. data/lib/aws/templates/help/rdoc/contextualized/filters/scoped.rb +29 -0
  77. data/lib/aws/templates/help/rdoc/contextualized/provider.rb +28 -0
  78. data/lib/aws/templates/help/rdoc/default.rb +12 -0
  79. data/lib/aws/templates/help/rdoc/default/definition.rb +89 -0
  80. data/lib/aws/templates/help/rdoc/default/provider.rb +25 -0
  81. data/lib/aws/templates/help/rdoc/dsl.rb +20 -0
  82. data/lib/aws/templates/help/rdoc/inheritable.rb +48 -0
  83. data/lib/aws/templates/help/rdoc/parametrized.rb +12 -0
  84. data/lib/aws/templates/help/rdoc/parametrized/constraint.rb +31 -0
  85. data/lib/aws/templates/help/rdoc/parametrized/constraints.rb +14 -0
  86. data/lib/aws/templates/help/rdoc/parametrized/constraints/all_of.rb +39 -0
  87. data/lib/aws/templates/help/rdoc/parametrized/constraints/condition.rb +44 -0
  88. data/lib/aws/templates/help/rdoc/parametrized/constraints/depends_on_value.rb +41 -0
  89. data/lib/aws/templates/help/rdoc/parametrized/constraints/enum.rb +33 -0
  90. data/lib/aws/templates/help/rdoc/parametrized/constraints/matches.rb +27 -0
  91. data/lib/aws/templates/help/rdoc/parametrized/constraints/not_nil.rb +27 -0
  92. data/lib/aws/templates/help/rdoc/parametrized/constraints/requires.rb +33 -0
  93. data/lib/aws/templates/help/rdoc/parametrized/constraints/satisfies_condition.rb +28 -0
  94. data/lib/aws/templates/help/rdoc/parametrized/getter.rb +17 -0
  95. data/lib/aws/templates/help/rdoc/parametrized/getters.rb +14 -0
  96. data/lib/aws/templates/help/rdoc/parametrized/nested.rb +32 -0
  97. data/lib/aws/templates/help/rdoc/parametrized/parameter.rb +55 -0
  98. data/lib/aws/templates/help/rdoc/parametrized/provider.rb +32 -0
  99. data/lib/aws/templates/help/rdoc/parametrized/transformation.rb +17 -0
  100. data/lib/aws/templates/help/rdoc/parametrized/transformations.rb +14 -0
  101. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_boolean.rb +25 -0
  102. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_chain.rb +34 -0
  103. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_hash.rb +40 -0
  104. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_integer.rb +26 -0
  105. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_list.rb +32 -0
  106. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_module.rb +25 -0
  107. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_object.rb +32 -0
  108. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_rendered.rb +28 -0
  109. data/lib/aws/templates/help/rdoc/parametrized/transformations/as_string.rb +25 -0
  110. data/lib/aws/templates/help/rdoc/provider.rb +20 -0
  111. data/lib/aws/templates/help/rdoc/routing.rb +104 -0
  112. data/lib/aws/templates/help/rdoc/texting.rb +42 -0
  113. data/lib/aws/templates/processor.rb +53 -0
  114. data/lib/aws/templates/processor/handler.rb +104 -0
  115. data/lib/aws/templates/processor/registry.rb +74 -0
  116. data/lib/aws/templates/processor/routing.rb +27 -0
  117. data/lib/aws/templates/render.rb +27 -25
  118. data/lib/aws/templates/render/basic_view.rb +47 -0
  119. data/lib/aws/templates/render/utils.rb +14 -0
  120. data/lib/aws/templates/render/utils/base_type_views.rb +12 -19
  121. data/lib/aws/templates/render/utils/inspect.rb +2 -4
  122. data/lib/aws/templates/render/utils/stringify.rb +2 -5
  123. data/lib/aws/templates/render/view.rb +3 -100
  124. data/lib/aws/templates/utils.rb +39 -15
  125. data/lib/aws/templates/utils/artifact_storage.rb +2 -3
  126. data/lib/aws/templates/utils/{named.rb → as_named.rb} +2 -3
  127. data/lib/aws/templates/utils/autoload.rb +224 -0
  128. data/lib/aws/templates/utils/contextualized.rb +8 -17
  129. data/lib/aws/templates/utils/contextualized/filter.rb +62 -0
  130. data/lib/aws/templates/utils/contextualized/filter/add.rb +67 -0
  131. data/lib/aws/templates/utils/contextualized/filter/chain.rb +56 -0
  132. data/lib/aws/templates/utils/contextualized/filter/copy.rb +38 -0
  133. data/lib/aws/templates/utils/contextualized/filter/dsl.rb +50 -0
  134. data/lib/aws/templates/utils/contextualized/filter/identity.rb +45 -0
  135. data/lib/aws/templates/utils/contextualized/filter/override.rb +62 -0
  136. data/lib/aws/templates/utils/contextualized/filter/proxy.rb +29 -0
  137. data/lib/aws/templates/utils/contextualized/filter/recursive_schema_filter.rb +46 -0
  138. data/lib/aws/templates/utils/contextualized/filter/remove.rb +66 -0
  139. data/lib/aws/templates/utils/contextualized/filter/scoped.rb +42 -0
  140. data/lib/aws/templates/utils/contextualized/refinements.rb +51 -0
  141. data/lib/aws/templates/utils/default.rb +258 -50
  142. data/lib/aws/templates/utils/dependency.rb +7 -6
  143. data/lib/aws/templates/utils/dependency/refinements.rb +80 -0
  144. data/lib/aws/templates/utils/dependent.rb +6 -3
  145. data/lib/aws/templates/utils/guarded.rb +30 -0
  146. data/lib/aws/templates/utils/inheritable.rb +21 -16
  147. data/lib/aws/templates/utils/inspectable.rb +4 -4
  148. data/lib/aws/templates/utils/late_bound.rb +2 -2
  149. data/lib/aws/templates/utils/memoized.rb +2 -0
  150. data/lib/aws/templates/utils/options.rb +49 -35
  151. data/lib/aws/templates/utils/parametrized.rb +32 -25
  152. data/lib/aws/templates/utils/parametrized/constraint.rb +95 -0
  153. data/lib/aws/templates/utils/parametrized/constraint/all_of.rb +51 -0
  154. data/lib/aws/templates/utils/parametrized/constraint/condition.rb +93 -0
  155. data/lib/aws/templates/utils/parametrized/constraint/depends_on_value.rb +60 -0
  156. data/lib/aws/templates/utils/parametrized/constraint/dsl.rb +86 -0
  157. data/lib/aws/templates/utils/parametrized/constraint/enum.rb +45 -0
  158. data/lib/aws/templates/utils/parametrized/constraint/matches.rb +44 -0
  159. data/lib/aws/templates/utils/parametrized/constraint/not_nil.rb +38 -0
  160. data/lib/aws/templates/utils/parametrized/constraint/requires.rb +54 -0
  161. data/lib/aws/templates/utils/parametrized/constraint/satisfies_condition.rb +55 -0
  162. data/lib/aws/templates/utils/parametrized/getter.rb +67 -0
  163. data/lib/aws/templates/utils/parametrized/getter/as_instance_variable.rb +41 -0
  164. data/lib/aws/templates/utils/parametrized/getter/as_is.rb +37 -0
  165. data/lib/aws/templates/utils/parametrized/getter/dsl.rb +62 -0
  166. data/lib/aws/templates/utils/parametrized/getter/one_of.rb +48 -0
  167. data/lib/aws/templates/utils/parametrized/getter/path.rb +53 -0
  168. data/lib/aws/templates/utils/parametrized/getter/value.rb +50 -0
  169. data/lib/aws/templates/utils/parametrized/nested.rb +9 -16
  170. data/lib/aws/templates/utils/parametrized/transformation.rb +74 -0
  171. data/lib/aws/templates/utils/parametrized/transformation/as_boolean.rb +42 -0
  172. data/lib/aws/templates/utils/parametrized/transformation/as_chain.rb +57 -0
  173. data/lib/aws/templates/utils/parametrized/transformation/as_hash.rb +89 -0
  174. data/lib/aws/templates/utils/parametrized/transformation/as_integer.rb +39 -0
  175. data/lib/aws/templates/utils/parametrized/transformation/as_list.rb +97 -0
  176. data/lib/aws/templates/utils/parametrized/transformation/as_module.rb +42 -0
  177. data/lib/aws/templates/utils/parametrized/transformation/as_object.rb +76 -0
  178. data/lib/aws/templates/utils/parametrized/transformation/as_rendered.rb +100 -0
  179. data/lib/aws/templates/utils/parametrized/transformation/as_string.rb +39 -0
  180. data/lib/aws/templates/utils/parametrized/transformation/dsl.rb +94 -0
  181. data/lib/aws/templates/utils/recursive.rb +22 -0
  182. data/spec/aws/templates/artifact_spec.rb +10 -10
  183. data/spec/aws/templates/cli_spec.rb +83 -0
  184. data/spec/aws/templates/composite_spec.rb +6 -4
  185. data/spec/aws/templates/help/rdoc/artifact_spec.rb +94 -0
  186. data/spec/aws/templates/help/rdoc/composite_spec.rb +53 -0
  187. data/spec/aws/templates/help/rdoc/parametrized/constraints/all_of_spec.rb +17 -0
  188. data/spec/aws/templates/help/rdoc/parametrized/constraints/depends_on_value_spec.rb +21 -0
  189. data/spec/aws/templates/help/rdoc/parametrized/constraints/enum_spec.rb +17 -0
  190. data/spec/aws/templates/help/rdoc/parametrized/constraints/matches_spec.rb +17 -0
  191. data/spec/aws/templates/help/rdoc/parametrized/constraints/satisfies_condition_spec.rb +17 -0
  192. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_boolean_spec.rb +17 -0
  193. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_chain_spec.rb +17 -0
  194. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_hash_spec.rb +72 -0
  195. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_integer_spec.rb +17 -0
  196. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_list_spec.rb +39 -0
  197. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_module_spec.rb +17 -0
  198. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_object_spec.rb +38 -0
  199. data/spec/aws/templates/help/rdoc/parametrized/transformations/as_rendered_spec.rb +17 -0
  200. data/spec/aws/templates/render/utils/base_type_views_spec.rb +9 -11
  201. data/spec/aws/templates/render_spec.rb +1 -1
  202. data/spec/aws/templates/utils/as_named_spec.rb +0 -2
  203. data/spec/aws/templates/utils/autoload_spec.rb +14 -0
  204. data/spec/aws/templates/utils/contextualized_spec.rb +5 -5
  205. data/spec/aws/templates/utils/late_bound_spec.rb +2 -2
  206. data/spec/aws/templates/utils/parametrized/constraint_spec.rb +8 -10
  207. data/spec/aws/templates/utils/parametrized/getters_spec.rb +6 -7
  208. data/spec/aws/templates/utils/parametrized/transformation_spec.rb +3 -6
  209. data/spec/aws/templates/utils/parametrized_spec.rb +9 -10
  210. data/spec/aws/templates/utils_spec.rb +18 -0
  211. data/spec/test_empty/stuff.rb +4 -0
  212. data/spec/test_empty/stuff/here/test.rb +9 -0
  213. metadata +235 -19
  214. data/lib/aws/templates/exceptions.rb +0 -221
  215. data/lib/aws/templates/render/registry.rb +0 -60
  216. data/lib/aws/templates/utils/contextualized/filters.rb +0 -437
  217. data/lib/aws/templates/utils/contextualized/hash.rb +0 -13
  218. data/lib/aws/templates/utils/contextualized/nil.rb +0 -13
  219. data/lib/aws/templates/utils/contextualized/proc.rb +0 -13
  220. data/lib/aws/templates/utils/dependency/enumerable.rb +0 -13
  221. data/lib/aws/templates/utils/dependency/object.rb +0 -46
  222. data/lib/aws/templates/utils/parametrized/constraints.rb +0 -423
  223. data/lib/aws/templates/utils/parametrized/getters.rb +0 -293
  224. data/lib/aws/templates/utils/parametrized/guarded.rb +0 -32
  225. data/lib/aws/templates/utils/parametrized/transformations.rb +0 -652
@@ -0,0 +1,22 @@
1
+ require 'aws/templates/utils'
2
+
3
+ module Aws
4
+ module Templates
5
+ module Utils
6
+ ##
7
+ # Recusrsive refinement
8
+ #
9
+ # The refinement adds to_recursive method to all standard classes which support recursive
10
+ # concept.
11
+ module Recursive
12
+ ##
13
+ # Hash implements resursive concept
14
+ refine ::Hash do
15
+ def to_recursive
16
+ self
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -25,7 +25,7 @@ describe Aws::Templates::Artifact do
25
25
  Struct.new(:root)
26
26
  end
27
27
 
28
- context 'featuring class is created' do
28
+ context 'when featuring class is created' do
29
29
  let(:featuring_class) { artifact_class.featuring(TestTest::A, TestTest::B) }
30
30
 
31
31
  it 'returns correct class name' do
@@ -33,7 +33,7 @@ describe Aws::Templates::Artifact do
33
33
  end
34
34
  end
35
35
 
36
- context 'instance created' do
36
+ context 'when instance created' do
37
37
  let(:params) do
38
38
  {
39
39
  c: 'qwe',
@@ -48,13 +48,13 @@ describe Aws::Templates::Artifact do
48
48
 
49
49
  let(:instance) { artifact_class.new(params) }
50
50
 
51
- context 'label is not specified' do
51
+ context 'without label' do
52
52
  it 'contains auto-generated label' do
53
53
  expect(instance.label).not_to be_nil
54
54
  end
55
55
  end
56
56
 
57
- context 'root is not specified' do
57
+ context 'without root' do
58
58
  it 'root is not empty' do
59
59
  expect(instance.root).not_to be_nil
60
60
  end
@@ -62,13 +62,13 @@ describe Aws::Templates::Artifact do
62
62
  expect(instance.dependencies).to be_empty
63
63
  end
64
64
  end
65
- context 'label is specified' do
65
+ context 'with label' do
66
66
  before { params[:label] = 'b' }
67
67
  it 'contains passed label' do
68
68
  expect(instance.label).to be == 'b'
69
69
  end
70
70
  end
71
- context 'root is specified' do
71
+ context 'with root' do
72
72
  before { params[:root] = 1 }
73
73
  it 'contains one dependency' do
74
74
  expect(instance.dependencies).to be == [just_object.new(1)].to_set
@@ -77,13 +77,13 @@ describe Aws::Templates::Artifact do
77
77
  expect(instance.root).to be == 1
78
78
  end
79
79
  end
80
- context 'different root is specified' do
80
+ context 'with different root' do
81
81
  before { params[:root] = 2 }
82
82
  it 'contains one dependency' do
83
83
  expect(instance.dependencies).to be == [just_object.new(2)].to_set
84
84
  end
85
85
  end
86
- context 'no overrides specified' do
86
+ context 'without overrides' do
87
87
  before { params.merge!(root: 3, label: 'thing') }
88
88
 
89
89
  let(:expected) do
@@ -106,7 +106,7 @@ describe Aws::Templates::Artifact do
106
106
  expect(instance.options.to_hash).to be == expected
107
107
  end
108
108
  end
109
- context 'override is present in input hash' do
109
+ context 'with override' do
110
110
  before { params.merge!(root: 3, label: 'thing', a: 'rty') }
111
111
 
112
112
  let(:expected) do
@@ -131,7 +131,7 @@ describe Aws::Templates::Artifact do
131
131
  end
132
132
  end
133
133
 
134
- context 'instance of child class created' do
134
+ context 'when instance of child class created' do
135
135
  let(:child_class) do
136
136
  Class.new(artifact_class) do
137
137
  default a: deleted,
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ module DummyRender
5
+ extend Aws::Templates::Render
6
+
7
+ define_view(Aws::Templates::Artifact) do
8
+ def to_rendered
9
+ instance.options.to_hash.to_a
10
+ end
11
+ end
12
+ end
13
+
14
+ class StubShell < ::Thor::Shell::Basic
15
+ def initialize(output, error)
16
+ @output = output
17
+ @error = error
18
+ super()
19
+ end
20
+
21
+ protected
22
+
23
+ def stdout
24
+ @output || STDOUT
25
+ end
26
+
27
+ def stderr
28
+ @error || STDERR
29
+ end
30
+ end
31
+
32
+ describe Aws::Templates::Cli do
33
+ let(:parameters) {}
34
+
35
+ let(:command) {}
36
+
37
+ let(:arguments) {}
38
+
39
+ let(:argv) { [command].concat(arguments).concat(parameters.map { |k, v| "#{k}#{v}" }) }
40
+
41
+ let(:stdout) { StringIO.new('', 'w+') }
42
+
43
+ let(:stderr) { StringIO.new('', 'w+') }
44
+
45
+ let(:shell) { StubShell.new(stdout, stderr) }
46
+
47
+ describe 'render' do
48
+ let(:parameters) do
49
+ {
50
+ '--render=' => 'DummyRender',
51
+ '--options=' => { label: 1, root: 2 }.to_json
52
+ }
53
+ end
54
+
55
+ let(:command) { 'render' }
56
+
57
+ let(:arguments) { ['Aws::Templates::Artifact'] }
58
+
59
+ before do
60
+ described_class.start(argv, shell: shell)
61
+ end
62
+
63
+ it 'prints rendered output' do
64
+ expect(stdout.string).to be == "[[\"label\",1],[\"root\",2]]\n"
65
+ end
66
+ end
67
+
68
+ describe 'document' do
69
+ let(:parameters) { {} }
70
+
71
+ let(:command) { 'document' }
72
+
73
+ let(:arguments) { ['Aws::Templates::Artifact'] }
74
+
75
+ before do
76
+ described_class.start(argv, shell: shell)
77
+ end
78
+
79
+ it 'prints documentation' do
80
+ expect(stdout.string).to match(/Artifact.*Parents.*Parameters/m)
81
+ end
82
+ end
83
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'aws/templates/composite'
3
3
 
4
+ using Aws::Templates::Utils::Dependency::Refinements
5
+
4
6
  class A
5
7
  attr_reader :params
6
8
 
@@ -54,7 +56,7 @@ describe Aws::Templates::Composite do
54
56
  instance.artifacts.each_with_object({}) { |(k, v), memo| memo[k] = v.params.to_hash }
55
57
  end
56
58
 
57
- context 'a parameter is overriden' do
59
+ context 'when a parameter is overriden' do
58
60
  let(:instance) { composite_class.new(parameters) }
59
61
 
60
62
  let(:result) do
@@ -312,7 +314,7 @@ describe Aws::Templates::Composite do
312
314
  }
313
315
  end
314
316
 
315
- context 'using constructor block' do
317
+ context 'when using constructor block' do
316
318
  let(:instance) do
317
319
  composite_class.new(parameters) do
318
320
  artifact(
@@ -326,7 +328,7 @@ describe Aws::Templates::Composite do
326
328
  it_behaves_like 'an artifact storage'
327
329
  end
328
330
 
329
- context 'using instance components method' do
331
+ context 'when using instance components method' do
330
332
  let(:instance) do
331
333
  composite_class.new(parameters).components do
332
334
  artifact(
@@ -340,7 +342,7 @@ describe Aws::Templates::Composite do
340
342
  it_behaves_like 'an artifact storage'
341
343
  end
342
344
 
343
- context 'using subclass' do
345
+ context 'when using subclass' do
344
346
  let(:subclass) do
345
347
  Class.new(composite_class) do
346
348
  components do
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ describe Aws::Templates::Help::Rdoc::Artifact do
5
+ let(:klass) do
6
+ Class.new(Aws::Templates::Artifact) do
7
+ help 'Very good thing'
8
+
9
+ def self.name
10
+ 'Test'
11
+ end
12
+
13
+ default undocumented: 3,
14
+ label: :ert,
15
+ root: :a
16
+
17
+ default :ancestors.to_proc
18
+
19
+ default a: { b: :name.to_proc }
20
+
21
+ default a: { b: { d: 1 } }
22
+
23
+ parameter :undocumented
24
+ parameter :undocumented_with_constraint, constraint: not_nil
25
+ parameter :undocumented_with_constraint_and_transform,
26
+ constraint: not_nil,
27
+ transform: as_string
28
+ parameter :documented,
29
+ description: 'Documented parameter'
30
+ parameter :documented_with_constraint,
31
+ description: 'Documented parameter with constraint',
32
+ constraint: enum(1, 2, 3)
33
+ parameter :documented_with_constraint_and_transform,
34
+ description: 'Documented parameter with constraint and transformation',
35
+ constraint: all_of(
36
+ not_nil,
37
+ satisfies('not too big') { |v| v.size < 10 }
38
+ ),
39
+ transform: as_list
40
+ end
41
+ end
42
+
43
+ let(:help) { Aws::Templates::Help::Rdoc.show(klass) }
44
+
45
+ let(:blurb) do
46
+ "\e[0m \n" \
47
+ "\e[1mTest\e[m\n" \
48
+ " \e[4mParents\e[m: Aws::Templates::Artifact\n\n" \
49
+ " \e[4mDescription\e[m\n" \
50
+ " Very good thing\n\n\n" \
51
+ " \e[4mParameters\e[m\n" \
52
+ " * \e[4mlabel\e[m Artifact's label\n" \
53
+ " * constraint:\n" \
54
+ " * can't be nil\n" \
55
+ " * \e[4mparent\e[m Artifact parent\n" \
56
+ " * \e[4mundocumented\e[m \n" \
57
+ " * \e[4mundocumented_with_constraint\e[m \n" \
58
+ " * constraint:\n" \
59
+ " * can't be nil\n" \
60
+ " * \e[4mundocumented_with_constraint_and_transform\e[m \n" \
61
+ " * transformation:\n" \
62
+ " * to string\n" \
63
+ " * constraint:\n" \
64
+ " * can't be nil\n" \
65
+ " * \e[4mdocumented\e[m Documented parameter\n" \
66
+ " * \e[4mdocumented_with_constraint\e[m Documented parameter with constraint\n" \
67
+ " * constraint:\n" \
68
+ " * one of: 1,2,3\n" \
69
+ " * \e[4mdocumented_with_constraint_and_transform\e[m Documented parameter with\n" \
70
+ " constraint and transformation\n" \
71
+ " * transformation:\n" \
72
+ " * as a list where elements can be anything\n" \
73
+ " * constraint:\n" \
74
+ " * satisfies all of the following:\n" \
75
+ " * can't be nil\n" \
76
+ " * not too big\n\n" \
77
+ " \e[4mDefaults\e[m\n" \
78
+ " * \e[4mlabel\e[m :ert\n" \
79
+ " * \e[4mroot\e[m :a\n" \
80
+ " * \e[4mundocumented\e[m 3\n" \
81
+ " \e[4moverlayed\e[m \e[4mwith\e[m\n" \
82
+ " Calculated\n" \
83
+ " \e[4moverlayed\e[m \e[4mwith\e[m\n" \
84
+ " * \e[4ma\e[m\n" \
85
+ " * \e[4mb\e[m Calculated\n" \
86
+ " \e[4moverlayed\e[m \e[4mwith\e[m\n" \
87
+ " \e[4mb\e[m\n" \
88
+ " * \e[4md\e[m 1\n\n\n"
89
+ end
90
+
91
+ it 'generates help correctly' do
92
+ expect(help).to be == blurb
93
+ end
94
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ class RdocTestComposite < Aws::Templates::Composite
5
+ help 'Very good thing'
6
+
7
+ default undocumented: 3,
8
+ label: 23,
9
+ root: 56
10
+
11
+ parameter :undocumented
12
+
13
+ contextualize filter(:copy)
14
+ end
15
+
16
+ describe Aws::Templates::Help::Rdoc::Composite do
17
+ let(:blurb) do
18
+ "\e[0m \n" \
19
+ "\e[1mRdocTestComposite\e[m\n" \
20
+ " \e[4mParents\e[m: Aws::Templates::Composite->Aws::Templates::Artifact\n\n" \
21
+ " \e[4mDescription\e[m\n" \
22
+ " Very good thing\n\n\n" \
23
+ " \e[4mParameters\e[m\n" \
24
+ " * \e[4mlabel\e[m Artifact's label\n" \
25
+ " * constraint:\n" \
26
+ " * can't be nil\n" \
27
+ " * \e[4mparent\e[m Artifact parent\n" \
28
+ " * \e[4mundocumented\e[m \n\n" \
29
+ " \e[4mDefaults\e[m\n" \
30
+ " * \e[4mlabel\e[m 23\n" \
31
+ " * \e[4mroot\e[m 56\n" \
32
+ " * \e[4mundocumented\e[m 3\n\n\n" \
33
+ " \e[4mComponents\e[m \e[4mscope\e[m \e[4mfilters\e[m\n" \
34
+ " * a chain of the following filters:\n" \
35
+ " * merge the following options from the parent context:\n" \
36
+ " * [:root]\n" \
37
+ " * merge the context with the following override:\n"
38
+ end
39
+
40
+ let(:help) { Aws::Templates::Help::Rdoc.show(RdocTestComposite) }
41
+
42
+ it 'generates help blurb correctly' do
43
+ expect(help.include?(blurb)).to be true
44
+ end
45
+
46
+ it 'generates defaults correctly' do
47
+ expect(help).to match(/undocumented.*3/m)
48
+ end
49
+
50
+ it 'generates context filters' do
51
+ expect(help).to match(/Components[^\n]+scope.*copy the entire/m)
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ describe Aws::Templates::Help::Rdoc::Parametrized::Constraints::AllOf do
5
+ let(:parametrized) do
6
+ Module.new do
7
+ include Aws::Templates::Utils::Parametrized
8
+ parameter :all_of_field, constraint: all_of(not_nil, enum(:a, :b, :c))
9
+ end
10
+ end
11
+
12
+ let(:help) { Aws::Templates::Help::Rdoc.show(parametrized) }
13
+
14
+ it 'prints documentation' do
15
+ expect(help).to match(/all_of_field.*be nil.*one of.*a..b..c/m)
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ describe Aws::Templates::Help::Rdoc::Parametrized::Constraints::DependsOnValue do
5
+ let(:parametrized) do
6
+ Module.new do
7
+ include Aws::Templates::Utils::Parametrized
8
+ parameter :field
9
+ parameter :depends_on_value_requires_field,
10
+ constraint: depends_on_value(a: requires(:field))
11
+ end
12
+ end
13
+
14
+ let(:help) { Aws::Templates::Help::Rdoc.show(parametrized) }
15
+
16
+ it 'prints documentation' do
17
+ expect(help).to match(
18
+ /depends_on_value_requires_field.*depends.*when[^\n]+a.*requires.*field/m
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ describe Aws::Templates::Help::Rdoc::Parametrized::Constraints::Enum do
5
+ let(:parametrized) do
6
+ Module.new do
7
+ include Aws::Templates::Utils::Parametrized
8
+ parameter :enum_field, constraint: enum(1, 2, '3')
9
+ end
10
+ end
11
+
12
+ let(:help) { Aws::Templates::Help::Rdoc.show(parametrized) }
13
+
14
+ it 'prints documentation' do
15
+ expect(help).to match(/enum_field.*one of.+1.+2.+3/m)
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'aws/templates/utils'
3
+
4
+ describe Aws::Templates::Help::Rdoc::Parametrized::Constraints::Matches do
5
+ let(:parametrized) do
6
+ Module.new do
7
+ include Aws::Templates::Utils::Parametrized
8
+ parameter :matches_field, constraint: matches(/ABC/)
9
+ end
10
+ end
11
+
12
+ let(:help) { Aws::Templates::Help::Rdoc.show(parametrized) }
13
+
14
+ it 'prints documentation' do
15
+ expect(help).to match(/matches_field.*matches.*ABC/m)
16
+ end
17
+ end