cloud-templates 0.2.0 → 0.3.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 +4 -4
- data/.rspec +4 -0
- data/.rubocop.yml +1 -0
- data/Rakefile +1 -1
- data/bin/cloud-templates-runner.rb +5 -0
- data/cloud-templates.gemspec +9 -4
- data/examples/lib/user_directory.rb +0 -10
- data/examples/lib/user_directory/artifacts.rb +8 -0
- data/examples/lib/user_directory/artifacts/catalogized.rb +8 -7
- data/examples/lib/user_directory/artifacts/group.rb +27 -30
- data/examples/lib/user_directory/artifacts/ided.rb +8 -7
- data/examples/lib/user_directory/artifacts/organization.rb +10 -11
- data/examples/lib/user_directory/artifacts/pathed.rb +17 -17
- data/examples/lib/user_directory/artifacts/person.rb +20 -15
- data/examples/lib/user_directory/artifacts/team.rb +26 -21
- data/examples/lib/user_directory/artifacts/unit.rb +15 -17
- data/examples/lib/user_directory/artifacts/user.rb +26 -23
- data/examples/lib/user_directory/render.rb +8 -0
- data/examples/lib/user_directory/render/etc.rb +2 -0
- data/examples/lib/user_directory/render/etc/artifact_view.rb +2 -2
- data/examples/lib/user_directory/render/etc/composite_view.rb +1 -2
- data/examples/lib/user_directory/render/etc/group_view.rb +3 -3
- data/examples/lib/user_directory/render/etc/person_view.rb +2 -2
- data/examples/lib/user_directory/render/etc/registry.rb +4 -6
- data/examples/lib/user_directory/render/etc/user_view.rb +2 -3
- data/examples/lib/user_directory/render/ldap.rb +2 -0
- data/examples/lib/user_directory/render/ldap/artifact_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/composite_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/group_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/organization_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/person_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/registry.rb +3 -4
- data/examples/lib/user_directory/render/ldap/unit_view.rb +3 -4
- data/examples/lib/user_directory/render/ldap/user_view.rb +3 -4
- data/examples/lib/user_directory/utils.rb +1 -1
- data/examples/spec/user_directory_spec.rb +24 -25
- data/lib/aws/templates.rb +0 -8
- data/lib/aws/templates/artifact.rb +20 -12
- data/lib/aws/templates/cli.rb +14 -0
- data/lib/aws/templates/cli/formatter.rb +21 -0
- data/lib/aws/templates/cli/formatter/json.rb +20 -0
- data/lib/aws/templates/cli/interface.rb +92 -0
- data/lib/aws/templates/composite.rb +6 -9
- data/lib/aws/templates/exception.rb +8 -0
- data/lib/aws/templates/exception/nested_parameter_exception.rb +19 -0
- data/lib/aws/templates/exception/option_error.rb +14 -0
- data/lib/aws/templates/exception/option_scalar_on_the_way.rb +26 -0
- data/lib/aws/templates/exception/option_should_be_recursive.rb +20 -0
- data/lib/aws/templates/exception/option_value_deleted.rb +22 -0
- data/lib/aws/templates/exception/parameter_already_exist.rb +26 -0
- data/lib/aws/templates/exception/parameter_exception.rb +26 -0
- data/lib/aws/templates/exception/parameter_getter_is_not_defined.rb +23 -0
- data/lib/aws/templates/exception/parameter_method_name_conflict.rb +26 -0
- data/lib/aws/templates/exception/parameter_specification_is_invalid.rb +30 -0
- data/lib/aws/templates/exception/parameter_value_invalid.rb +37 -0
- data/lib/aws/templates/exception/parametrized_dsl_error.rb +14 -0
- data/lib/aws/templates/exception/view_not_found.rb +26 -0
- data/lib/aws/templates/help.rb +43 -0
- data/lib/aws/templates/help/aggregate.rb +74 -0
- data/lib/aws/templates/help/dsl.rb +30 -0
- data/lib/aws/templates/help/provider.rb +15 -0
- data/lib/aws/templates/help/rdoc.rb +105 -0
- data/lib/aws/templates/help/rdoc/artifact.rb +50 -0
- data/lib/aws/templates/help/rdoc/composite.rb +20 -0
- data/lib/aws/templates/help/rdoc/contextualized.rb +12 -0
- data/lib/aws/templates/help/rdoc/contextualized/filter.rb +19 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters.rb +14 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/add.rb +21 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/chain.rb +33 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/copy.rb +23 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/identity.rb +23 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/override.rb +29 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/proxy.rb +28 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/recursive_schema_filter.rb +28 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/remove.rb +21 -0
- data/lib/aws/templates/help/rdoc/contextualized/filters/scoped.rb +29 -0
- data/lib/aws/templates/help/rdoc/contextualized/provider.rb +28 -0
- data/lib/aws/templates/help/rdoc/default.rb +12 -0
- data/lib/aws/templates/help/rdoc/default/definition.rb +89 -0
- data/lib/aws/templates/help/rdoc/default/provider.rb +25 -0
- data/lib/aws/templates/help/rdoc/dsl.rb +20 -0
- data/lib/aws/templates/help/rdoc/inheritable.rb +48 -0
- data/lib/aws/templates/help/rdoc/parametrized.rb +12 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraint.rb +31 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints.rb +14 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/all_of.rb +39 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/condition.rb +44 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/depends_on_value.rb +41 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/enum.rb +33 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/matches.rb +27 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/not_nil.rb +27 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/requires.rb +33 -0
- data/lib/aws/templates/help/rdoc/parametrized/constraints/satisfies_condition.rb +28 -0
- data/lib/aws/templates/help/rdoc/parametrized/getter.rb +17 -0
- data/lib/aws/templates/help/rdoc/parametrized/getters.rb +14 -0
- data/lib/aws/templates/help/rdoc/parametrized/nested.rb +32 -0
- data/lib/aws/templates/help/rdoc/parametrized/parameter.rb +55 -0
- data/lib/aws/templates/help/rdoc/parametrized/provider.rb +32 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformation.rb +17 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations.rb +14 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_boolean.rb +25 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_chain.rb +34 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_hash.rb +40 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_integer.rb +26 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_list.rb +32 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_module.rb +25 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_object.rb +32 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_rendered.rb +28 -0
- data/lib/aws/templates/help/rdoc/parametrized/transformations/as_string.rb +25 -0
- data/lib/aws/templates/help/rdoc/provider.rb +20 -0
- data/lib/aws/templates/help/rdoc/routing.rb +104 -0
- data/lib/aws/templates/help/rdoc/texting.rb +42 -0
- data/lib/aws/templates/processor.rb +53 -0
- data/lib/aws/templates/processor/handler.rb +104 -0
- data/lib/aws/templates/processor/registry.rb +74 -0
- data/lib/aws/templates/processor/routing.rb +27 -0
- data/lib/aws/templates/render.rb +27 -25
- data/lib/aws/templates/render/basic_view.rb +47 -0
- data/lib/aws/templates/render/utils.rb +14 -0
- data/lib/aws/templates/render/utils/base_type_views.rb +12 -19
- data/lib/aws/templates/render/utils/inspect.rb +2 -4
- data/lib/aws/templates/render/utils/stringify.rb +2 -5
- data/lib/aws/templates/render/view.rb +3 -100
- data/lib/aws/templates/utils.rb +39 -15
- data/lib/aws/templates/utils/artifact_storage.rb +2 -3
- data/lib/aws/templates/utils/{named.rb → as_named.rb} +2 -3
- data/lib/aws/templates/utils/autoload.rb +224 -0
- data/lib/aws/templates/utils/contextualized.rb +8 -17
- data/lib/aws/templates/utils/contextualized/filter.rb +62 -0
- data/lib/aws/templates/utils/contextualized/filter/add.rb +67 -0
- data/lib/aws/templates/utils/contextualized/filter/chain.rb +56 -0
- data/lib/aws/templates/utils/contextualized/filter/copy.rb +38 -0
- data/lib/aws/templates/utils/contextualized/filter/dsl.rb +50 -0
- data/lib/aws/templates/utils/contextualized/filter/identity.rb +45 -0
- data/lib/aws/templates/utils/contextualized/filter/override.rb +62 -0
- data/lib/aws/templates/utils/contextualized/filter/proxy.rb +29 -0
- data/lib/aws/templates/utils/contextualized/filter/recursive_schema_filter.rb +46 -0
- data/lib/aws/templates/utils/contextualized/filter/remove.rb +66 -0
- data/lib/aws/templates/utils/contextualized/filter/scoped.rb +42 -0
- data/lib/aws/templates/utils/contextualized/refinements.rb +51 -0
- data/lib/aws/templates/utils/default.rb +258 -50
- data/lib/aws/templates/utils/dependency.rb +7 -6
- data/lib/aws/templates/utils/dependency/refinements.rb +80 -0
- data/lib/aws/templates/utils/dependent.rb +6 -3
- data/lib/aws/templates/utils/guarded.rb +30 -0
- data/lib/aws/templates/utils/inheritable.rb +21 -16
- data/lib/aws/templates/utils/inspectable.rb +4 -4
- data/lib/aws/templates/utils/late_bound.rb +2 -2
- data/lib/aws/templates/utils/memoized.rb +2 -0
- data/lib/aws/templates/utils/options.rb +49 -35
- data/lib/aws/templates/utils/parametrized.rb +32 -25
- data/lib/aws/templates/utils/parametrized/constraint.rb +95 -0
- data/lib/aws/templates/utils/parametrized/constraint/all_of.rb +51 -0
- data/lib/aws/templates/utils/parametrized/constraint/condition.rb +93 -0
- data/lib/aws/templates/utils/parametrized/constraint/depends_on_value.rb +60 -0
- data/lib/aws/templates/utils/parametrized/constraint/dsl.rb +86 -0
- data/lib/aws/templates/utils/parametrized/constraint/enum.rb +45 -0
- data/lib/aws/templates/utils/parametrized/constraint/matches.rb +44 -0
- data/lib/aws/templates/utils/parametrized/constraint/not_nil.rb +38 -0
- data/lib/aws/templates/utils/parametrized/constraint/requires.rb +54 -0
- data/lib/aws/templates/utils/parametrized/constraint/satisfies_condition.rb +55 -0
- data/lib/aws/templates/utils/parametrized/getter.rb +67 -0
- data/lib/aws/templates/utils/parametrized/getter/as_instance_variable.rb +41 -0
- data/lib/aws/templates/utils/parametrized/getter/as_is.rb +37 -0
- data/lib/aws/templates/utils/parametrized/getter/dsl.rb +62 -0
- data/lib/aws/templates/utils/parametrized/getter/one_of.rb +48 -0
- data/lib/aws/templates/utils/parametrized/getter/path.rb +53 -0
- data/lib/aws/templates/utils/parametrized/getter/value.rb +50 -0
- data/lib/aws/templates/utils/parametrized/nested.rb +9 -16
- data/lib/aws/templates/utils/parametrized/transformation.rb +74 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_boolean.rb +42 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_chain.rb +57 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_hash.rb +89 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_integer.rb +39 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_list.rb +97 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_module.rb +42 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_object.rb +76 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_rendered.rb +100 -0
- data/lib/aws/templates/utils/parametrized/transformation/as_string.rb +39 -0
- data/lib/aws/templates/utils/parametrized/transformation/dsl.rb +94 -0
- data/lib/aws/templates/utils/recursive.rb +22 -0
- data/spec/aws/templates/artifact_spec.rb +10 -10
- data/spec/aws/templates/cli_spec.rb +83 -0
- data/spec/aws/templates/composite_spec.rb +6 -4
- data/spec/aws/templates/help/rdoc/artifact_spec.rb +94 -0
- data/spec/aws/templates/help/rdoc/composite_spec.rb +53 -0
- data/spec/aws/templates/help/rdoc/parametrized/constraints/all_of_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/constraints/depends_on_value_spec.rb +21 -0
- data/spec/aws/templates/help/rdoc/parametrized/constraints/enum_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/constraints/matches_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/constraints/satisfies_condition_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_boolean_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_chain_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_hash_spec.rb +72 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_integer_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_list_spec.rb +39 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_module_spec.rb +17 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_object_spec.rb +38 -0
- data/spec/aws/templates/help/rdoc/parametrized/transformations/as_rendered_spec.rb +17 -0
- data/spec/aws/templates/render/utils/base_type_views_spec.rb +9 -11
- data/spec/aws/templates/render_spec.rb +1 -1
- data/spec/aws/templates/utils/as_named_spec.rb +0 -2
- data/spec/aws/templates/utils/autoload_spec.rb +14 -0
- data/spec/aws/templates/utils/contextualized_spec.rb +5 -5
- data/spec/aws/templates/utils/late_bound_spec.rb +2 -2
- data/spec/aws/templates/utils/parametrized/constraint_spec.rb +8 -10
- data/spec/aws/templates/utils/parametrized/getters_spec.rb +6 -7
- data/spec/aws/templates/utils/parametrized/transformation_spec.rb +3 -6
- data/spec/aws/templates/utils/parametrized_spec.rb +9 -10
- data/spec/aws/templates/utils_spec.rb +18 -0
- data/spec/test_empty/stuff.rb +4 -0
- data/spec/test_empty/stuff/here/test.rb +9 -0
- metadata +235 -19
- data/lib/aws/templates/exceptions.rb +0 -221
- data/lib/aws/templates/render/registry.rb +0 -60
- data/lib/aws/templates/utils/contextualized/filters.rb +0 -437
- data/lib/aws/templates/utils/contextualized/hash.rb +0 -13
- data/lib/aws/templates/utils/contextualized/nil.rb +0 -13
- data/lib/aws/templates/utils/contextualized/proc.rb +0 -13
- data/lib/aws/templates/utils/dependency/enumerable.rb +0 -13
- data/lib/aws/templates/utils/dependency/object.rb +0 -46
- data/lib/aws/templates/utils/parametrized/constraints.rb +0 -423
- data/lib/aws/templates/utils/parametrized/getters.rb +0 -293
- data/lib/aws/templates/utils/parametrized/guarded.rb +0 -32
- data/lib/aws/templates/utils/parametrized/transformations.rb +0 -652
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'aws/templates/utils/dependency/object'
|
|
3
|
-
require 'aws/templates/utils/dependency/enumerable'
|
|
4
|
-
require 'aws/templates/utils/inspectable'
|
|
1
|
+
require 'aws/templates/utils'
|
|
5
2
|
|
|
6
3
|
module Aws
|
|
7
4
|
module Templates
|
|
@@ -16,7 +13,9 @@ module Aws
|
|
|
16
13
|
# * Dependecy can be applied case-by-case basis whereas singleton is attached to the object
|
|
17
14
|
# itself
|
|
18
15
|
class Dependency < BasicObject
|
|
19
|
-
|
|
16
|
+
using Refinements
|
|
17
|
+
|
|
18
|
+
include ::Aws::Templates::Utils::Inspectable
|
|
20
19
|
|
|
21
20
|
##
|
|
22
21
|
# Equality
|
|
@@ -56,6 +55,8 @@ module Aws
|
|
|
56
55
|
attr_reader :object
|
|
57
56
|
attr_reader :dependencies
|
|
58
57
|
|
|
58
|
+
alias not_a_dependency object
|
|
59
|
+
|
|
59
60
|
##
|
|
60
61
|
# Redirect every method call to the proxied object if the object supports it
|
|
61
62
|
def method_missing(name, *args, &block)
|
|
@@ -65,7 +66,7 @@ module Aws
|
|
|
65
66
|
##
|
|
66
67
|
# It supports every method proxied object supports
|
|
67
68
|
def respond_to_missing?(name, include_private = false)
|
|
68
|
-
object.respond_to?(name, include_private)
|
|
69
|
+
object.respond_to?(name, include_private)
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
##
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
class Dependency
|
|
7
|
+
##
|
|
8
|
+
# Refinements for transparent dependecy handling
|
|
9
|
+
#
|
|
10
|
+
# Dependency mechanism requres transparent language support to work correctly with
|
|
11
|
+
# arbitrary objects and object collections. This refinement introduces methods used
|
|
12
|
+
# for dependency processing.
|
|
13
|
+
module Refinements
|
|
14
|
+
EMPTY_SET = ::Set.new.freeze
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Dependency method stubs
|
|
18
|
+
#
|
|
19
|
+
# To avoid checking classes directly to filter out dependencies and non-dependencies,
|
|
20
|
+
# we're monkey-patching Object class with stubs for Dependency class.
|
|
21
|
+
refine ::Object do
|
|
22
|
+
# By default an object is not a dependency
|
|
23
|
+
def dependency?
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# It returns self
|
|
28
|
+
def object
|
|
29
|
+
self
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Object root
|
|
34
|
+
#
|
|
35
|
+
# It is used to gracefully process dependencies
|
|
36
|
+
def root; end
|
|
37
|
+
|
|
38
|
+
alias_method :not_a_dependency, :object
|
|
39
|
+
|
|
40
|
+
# it returns a set containing a single dependency on itself
|
|
41
|
+
def dependencies
|
|
42
|
+
EMPTY_SET
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# mark the object as dependency
|
|
46
|
+
def as_a_dependency
|
|
47
|
+
Aws::Templates::Utils::Dependency.new(object)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# mark the object as dependency of itself
|
|
51
|
+
def as_a_self_dependency
|
|
52
|
+
as_a_dependency.to_self
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Methods to be added to all collections
|
|
63
|
+
#
|
|
64
|
+
# NOTICE: We are not using refinements for it because of Ruby 2.3 support. This version doesn't
|
|
65
|
+
# support mixin-level refinements.
|
|
66
|
+
module Enumerable
|
|
67
|
+
using Aws::Templates::Utils::Dependency::Refinements
|
|
68
|
+
|
|
69
|
+
def dependencies
|
|
70
|
+
# rubocop:disable Style/SymbolProc
|
|
71
|
+
# Refinements don't support dynamic dispatch yet. So, symbolic methods don't work
|
|
72
|
+
find_all { |obj| obj.dependency? }
|
|
73
|
+
.inject(::Set.new) { |acc, elem| acc.merge(elem.dependencies) }
|
|
74
|
+
# rubocop:enable Style/SymbolProc
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def dependency?
|
|
78
|
+
true
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require 'aws/templates/utils
|
|
2
|
-
require 'set'
|
|
1
|
+
require 'aws/templates/utils'
|
|
3
2
|
|
|
4
3
|
module Aws
|
|
5
4
|
module Templates
|
|
@@ -10,6 +9,8 @@ module Aws
|
|
|
10
9
|
# Introduces methods needed to track dependencies of an object. The object needs to implement
|
|
11
10
|
# options method and root method.
|
|
12
11
|
module Dependent
|
|
12
|
+
using Utils::Dependency::Refinements
|
|
13
|
+
|
|
13
14
|
##
|
|
14
15
|
# Introduce dependencies manually
|
|
15
16
|
#
|
|
@@ -17,7 +18,9 @@ module Aws
|
|
|
17
18
|
# of all dependencies automatically. If some dependency is not logical/parametrical but
|
|
18
19
|
# purely chronological, it can be introduced into the dependency list with this method.
|
|
19
20
|
def depends_on(*depends)
|
|
20
|
-
new_dependencies = depends.dependencies
|
|
21
|
+
new_dependencies = depends.map { |obj| obj.dependency? ? obj.dependencies : Set[obj] }
|
|
22
|
+
.reduce(&:merge)
|
|
23
|
+
|
|
21
24
|
new_dependencies.select! { |obj| obj.root == root } unless root.nil?
|
|
22
25
|
dependencies.merge(new_dependencies)
|
|
23
26
|
self
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
##
|
|
7
|
+
# Remember Alan Turing's halting problem and don't believe in miracles. The method will
|
|
8
|
+
# only work with parameters because they are supposed to be pure unmodifying functions.
|
|
9
|
+
# Hence we can terminate if a parameter method was invoked twice in the stack with the same
|
|
10
|
+
# context.
|
|
11
|
+
module Guarded
|
|
12
|
+
Call = Struct.new(:instance, :entity)
|
|
13
|
+
|
|
14
|
+
def guarded_for(instance, entity)
|
|
15
|
+
current_call = Call.new(instance, entity)
|
|
16
|
+
return unless trace.add?(current_call)
|
|
17
|
+
ret = yield
|
|
18
|
+
trace.delete(current_call)
|
|
19
|
+
ret
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def trace
|
|
25
|
+
Thread.current[Guarded.name] ||= ::Set.new
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
1
3
|
module Aws
|
|
2
4
|
module Templates
|
|
3
5
|
module Utils
|
|
@@ -11,14 +13,20 @@ module Aws
|
|
|
11
13
|
# in every including module/class to expose appropriate module-level primitives for
|
|
12
14
|
# handling inheritance of class-scope methods.
|
|
13
15
|
module ClassMethods
|
|
14
|
-
|
|
16
|
+
##
|
|
17
|
+
# Empty class scope
|
|
18
|
+
#
|
|
19
|
+
# Identity class scope which contains nothing. Used as base case for class scope
|
|
20
|
+
# inheritance hierarchy.
|
|
21
|
+
module ClassScope
|
|
22
|
+
end
|
|
15
23
|
|
|
16
24
|
##
|
|
17
25
|
# To add class methods also while including the module
|
|
18
26
|
def included(base)
|
|
19
27
|
super(base)
|
|
20
|
-
base.extend(
|
|
21
|
-
base.
|
|
28
|
+
base.extend(ClassMethods)
|
|
29
|
+
base.extend(ClassScope)
|
|
22
30
|
end
|
|
23
31
|
|
|
24
32
|
def instance_scope(&blk)
|
|
@@ -26,22 +34,19 @@ module Aws
|
|
|
26
34
|
end
|
|
27
35
|
|
|
28
36
|
def class_scope(&blk)
|
|
29
|
-
if blk
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@class_scope
|
|
37
|
+
raise ScriptError.new('class_scope should have a block') if blk.nil?
|
|
38
|
+
_define_class_scope unless _class_scope_defined?
|
|
39
|
+
ClassScope.module_eval(&blk)
|
|
40
|
+
extend ClassScope
|
|
35
41
|
end
|
|
36
42
|
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else
|
|
41
|
-
@class_scope.include(mod)
|
|
42
|
-
end
|
|
43
|
+
def _class_scope_defined?
|
|
44
|
+
@class_scope_defined || false
|
|
45
|
+
end
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
def _define_class_scope
|
|
48
|
+
const_set(:ClassScope, ClassScope.dup)
|
|
49
|
+
@class_scope_defined = true
|
|
45
50
|
end
|
|
46
51
|
end
|
|
47
52
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
1
3
|
module Aws
|
|
2
4
|
module Templates
|
|
3
5
|
module Utils
|
|
@@ -8,13 +10,11 @@ module Aws
|
|
|
8
10
|
# mechanism.
|
|
9
11
|
module Inspectable
|
|
10
12
|
def to_s
|
|
11
|
-
::
|
|
12
|
-
::Aws::Templates::Render::Utils::Stringify.view_for(self).to_rendered
|
|
13
|
+
Render::Utils::Stringify.view_for(self).to_rendered
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def inspect
|
|
16
|
-
::
|
|
17
|
-
::Aws::Templates::Render::Utils::Inspect.view_for(self).to_rendered
|
|
17
|
+
Render::Utils::Inspect.view_for(self).to_rendered
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require 'aws/templates/utils
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
2
|
|
|
3
3
|
module Aws
|
|
4
4
|
module Templates
|
|
@@ -12,7 +12,7 @@ module Aws
|
|
|
12
12
|
#
|
|
13
13
|
# The module provides DSL for creating late binding points known as References.
|
|
14
14
|
module LateBound
|
|
15
|
-
include Inheritable
|
|
15
|
+
include Utils::Inheritable
|
|
16
16
|
|
|
17
17
|
##
|
|
18
18
|
# Reference
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
require 'set'
|
|
2
|
-
require 'aws/templates/exceptions'
|
|
3
1
|
require 'aws/templates/utils'
|
|
4
|
-
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/ClassLength
|
|
5
4
|
|
|
6
5
|
module Aws
|
|
7
6
|
module Templates
|
|
8
7
|
module Utils
|
|
9
|
-
# rubocop:disable Metrics/ClassLength
|
|
10
|
-
|
|
11
8
|
##
|
|
12
9
|
# Options hash-like class
|
|
13
10
|
#
|
|
@@ -19,7 +16,15 @@ module Aws
|
|
|
19
16
|
# select the best combination if it doesn't see the exact match
|
|
20
17
|
# during lookup.
|
|
21
18
|
class Options
|
|
22
|
-
|
|
19
|
+
using Utils::Contextualized::Refinements
|
|
20
|
+
using Utils::Dependency::Refinements
|
|
21
|
+
|
|
22
|
+
include Utils::Memoized
|
|
23
|
+
include Templates::Exception
|
|
24
|
+
|
|
25
|
+
def structures
|
|
26
|
+
@structures ||= []
|
|
27
|
+
end
|
|
23
28
|
|
|
24
29
|
##
|
|
25
30
|
# Get a parameter from resulting hash or any nested part of it
|
|
@@ -51,10 +56,10 @@ module Aws
|
|
|
51
56
|
# # multi-level wildcard match
|
|
52
57
|
# opts['a', 'z', 'r'] # => 2
|
|
53
58
|
def [](*path)
|
|
54
|
-
|
|
59
|
+
structures.reverse_each.inject(nil) do |memo, container|
|
|
55
60
|
ret = begin
|
|
56
61
|
Utils.lookup(container, path.dup)
|
|
57
|
-
rescue OptionValueDeleted, OptionScalarOnTheWay
|
|
62
|
+
rescue Exception::OptionValueDeleted, Exception::OptionScalarOnTheWay
|
|
58
63
|
# we discovered that this layer either have value deleted or parent was overriden
|
|
59
64
|
# by a scalar. Either way we just return what we have in the memo
|
|
60
65
|
break memo
|
|
@@ -77,10 +82,13 @@ module Aws
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def dependencies
|
|
85
|
+
# rubocop:disable Style/SymbolProc
|
|
86
|
+
# Refinements don't support dynamic dispatch yet. So, symbolic methods don't work
|
|
80
87
|
memoize(:dependencies) do
|
|
81
|
-
select_recursively
|
|
82
|
-
.inject(Set.new) { |acc, elem| acc.merge(elem.dependencies) }
|
|
88
|
+
select_recursively { |obj| obj.dependency? }
|
|
89
|
+
.inject(::Set.new) { |acc, elem| acc.merge(elem.dependencies) }
|
|
83
90
|
end
|
|
91
|
+
# rubocop:enable Style/SymbolProc
|
|
84
92
|
end
|
|
85
93
|
|
|
86
94
|
def select_recursively(&blk)
|
|
@@ -113,7 +121,7 @@ module Aws
|
|
|
113
121
|
value = path_and_value.pop
|
|
114
122
|
path = path_and_value
|
|
115
123
|
dirty!.cow! # mooo
|
|
116
|
-
Utils.set_recursively(
|
|
124
|
+
Utils.set_recursively(structures.last, value, path)
|
|
117
125
|
end
|
|
118
126
|
|
|
119
127
|
##
|
|
@@ -123,7 +131,7 @@ module Aws
|
|
|
123
131
|
# with special marker that it was deleted. It helps avoid hash recalculation leading to
|
|
124
132
|
# memory thrashing simultaneously maintaining semantics close to Hash#delete
|
|
125
133
|
def delete(*path)
|
|
126
|
-
self[*path] = DELETED_MARKER
|
|
134
|
+
self[*path] = Utils::DELETED_MARKER
|
|
127
135
|
end
|
|
128
136
|
|
|
129
137
|
##
|
|
@@ -133,7 +141,7 @@ module Aws
|
|
|
133
141
|
# recursively.
|
|
134
142
|
def to_hash
|
|
135
143
|
memoize(:to_hash) do
|
|
136
|
-
_process_hashed(
|
|
144
|
+
_process_hashed(structures.inject({}) { |acc, elem| Utils.merge(acc, elem) })
|
|
137
145
|
end
|
|
138
146
|
end
|
|
139
147
|
|
|
@@ -156,10 +164,10 @@ module Aws
|
|
|
156
164
|
# Produces a list of top-level keys from all layers. Deleted branches are not included.
|
|
157
165
|
def keys
|
|
158
166
|
memoize(:keys) do
|
|
159
|
-
|
|
160
|
-
.each_with_object(Set.new) do |container, keyset|
|
|
167
|
+
structures
|
|
168
|
+
.each_with_object(::Set.new) do |container, keyset|
|
|
161
169
|
container.keys.each do |k|
|
|
162
|
-
container[k] == DELETED_MARKER ? keyset.delete(k) : keyset.add(k)
|
|
170
|
+
container[k] == Utils::DELETED_MARKER ? keyset.delete(k) : keyset.add(k)
|
|
163
171
|
end
|
|
164
172
|
end
|
|
165
173
|
.to_a
|
|
@@ -171,8 +179,8 @@ module Aws
|
|
|
171
179
|
#
|
|
172
180
|
# Checks if top-level key exists. Deleted branches are excluded.
|
|
173
181
|
def include?(k)
|
|
174
|
-
found =
|
|
175
|
-
!found.nil? && (found[k] != DELETED_MARKER)
|
|
182
|
+
found = structures.reverse_each.find { |container| container.include?(k) }
|
|
183
|
+
!found.nil? && (found[k] != Utils::DELETED_MARKER)
|
|
176
184
|
end
|
|
177
185
|
|
|
178
186
|
##
|
|
@@ -182,7 +190,7 @@ module Aws
|
|
|
182
190
|
# The object must be "recusrsive" meaning it should satisfy minimum contract for
|
|
183
191
|
# "recursive". See Utils::recursive? for details
|
|
184
192
|
def merge(other)
|
|
185
|
-
self.class.new(
|
|
193
|
+
self.class.new(*structures, other)
|
|
186
194
|
end
|
|
187
195
|
|
|
188
196
|
##
|
|
@@ -192,8 +200,14 @@ module Aws
|
|
|
192
200
|
# The object must be "recursive" meaning it should satisfy minimum contract for
|
|
193
201
|
# "recursive". See Utils::recursive? for details
|
|
194
202
|
def merge!(other)
|
|
195
|
-
raise OptionShouldBeRecursive.new(other) unless Utils.recursive?(other)
|
|
196
|
-
|
|
203
|
+
raise Exception::OptionShouldBeRecursive.new(other) unless Utils.recursive?(other)
|
|
204
|
+
|
|
205
|
+
if other.is_a?(self.class)
|
|
206
|
+
structures.concat(other.structures)
|
|
207
|
+
else
|
|
208
|
+
structures << other
|
|
209
|
+
end
|
|
210
|
+
|
|
197
211
|
dirty!
|
|
198
212
|
end
|
|
199
213
|
|
|
@@ -209,15 +223,7 @@ module Aws
|
|
|
209
223
|
##
|
|
210
224
|
# Initialize Options with list of recursive structures (See Options#recursive?)
|
|
211
225
|
def initialize(*structures)
|
|
212
|
-
|
|
213
|
-
if Utils.recursive?(container)
|
|
214
|
-
container
|
|
215
|
-
elsif Utils.hashable?(container)
|
|
216
|
-
container.to_hash
|
|
217
|
-
else
|
|
218
|
-
raise OptionShouldBeRecursive.new(container)
|
|
219
|
-
end
|
|
220
|
-
end
|
|
226
|
+
structures.reject(&:nil?).each { |container| merge!(container) }
|
|
221
227
|
end
|
|
222
228
|
|
|
223
229
|
##
|
|
@@ -226,7 +232,7 @@ module Aws
|
|
|
226
232
|
# Duplicates the object itself and puts another layer of hash map. All original hash maps
|
|
227
233
|
# are not touched if the duplicate is modified.
|
|
228
234
|
def dup
|
|
229
|
-
Options.new(
|
|
235
|
+
Options.new(*structures)
|
|
230
236
|
end
|
|
231
237
|
|
|
232
238
|
##
|
|
@@ -250,14 +256,20 @@ module Aws
|
|
|
250
256
|
# from ActiveSupport. It puts the "recursive" object passed to the bottom of the layer
|
|
251
257
|
# stack of the Options instance effectively making it the least prioritized layer.
|
|
252
258
|
def unshift_layer!(layer)
|
|
253
|
-
raise OptionShouldBeRecursive.new(layer) unless Utils.recursive?(layer)
|
|
254
|
-
|
|
259
|
+
raise Exception::OptionShouldBeRecursive.new(layer) unless Utils.recursive?(layer)
|
|
260
|
+
|
|
261
|
+
if layer.is_a?(self.class)
|
|
262
|
+
layer.structures.dup.concat(structures)
|
|
263
|
+
else
|
|
264
|
+
structures.unshift(layer)
|
|
265
|
+
end
|
|
266
|
+
|
|
255
267
|
dirty!
|
|
256
268
|
end
|
|
257
269
|
|
|
258
270
|
def cow!
|
|
259
271
|
unless @is_cowed
|
|
260
|
-
|
|
272
|
+
structures << {}
|
|
261
273
|
@is_cowed = true
|
|
262
274
|
end
|
|
263
275
|
|
|
@@ -269,7 +281,7 @@ module Aws
|
|
|
269
281
|
# :nodoc: process hashable recursively removing all keys marked as deleted
|
|
270
282
|
def _process_hashed(hashed)
|
|
271
283
|
hashed.each_pair do |key, value|
|
|
272
|
-
if value == DELETED_MARKER
|
|
284
|
+
if value == Utils::DELETED_MARKER
|
|
273
285
|
hashed.delete(key)
|
|
274
286
|
elsif Utils.hashable?(value)
|
|
275
287
|
_process_hashed(value.to_hash).freeze
|
|
@@ -282,3 +294,5 @@ module Aws
|
|
|
282
294
|
end
|
|
283
295
|
end
|
|
284
296
|
end
|
|
297
|
+
|
|
298
|
+
# rubocop:enable Metrics/ClassLength
|