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,8 +1,4 @@
|
|
|
1
|
-
require 'aws/templates/utils
|
|
2
|
-
require 'aws/templates/utils/contextualized/proc'
|
|
3
|
-
require 'aws/templates/utils/contextualized/hash'
|
|
4
|
-
require 'aws/templates/utils/contextualized/nil'
|
|
5
|
-
require 'aws/templates/utils/inheritable'
|
|
1
|
+
require 'aws/templates/utils'
|
|
6
2
|
|
|
7
3
|
module Aws
|
|
8
4
|
module Templates
|
|
@@ -22,7 +18,8 @@ module Aws
|
|
|
22
18
|
# by "filter" mixed method is a functor. No operations are performed
|
|
23
19
|
# on options.
|
|
24
20
|
module Contextualized
|
|
25
|
-
include Inheritable
|
|
21
|
+
include Utils::Inheritable
|
|
22
|
+
include Filter::Dsl
|
|
26
23
|
|
|
27
24
|
instance_scope do
|
|
28
25
|
##
|
|
@@ -35,7 +32,7 @@ module Aws
|
|
|
35
32
|
# The method is working correctly with both parent classes and all
|
|
36
33
|
# Contextualized mixins used in between.
|
|
37
34
|
def context
|
|
38
|
-
@context ||=
|
|
35
|
+
@context ||= Filter::Scoped.new(self.class.context, self)
|
|
39
36
|
end
|
|
40
37
|
|
|
41
38
|
##
|
|
@@ -48,14 +45,14 @@ module Aws
|
|
|
48
45
|
if blk
|
|
49
46
|
clone._set_context(context.scoped_filter & arg).instance_exec(&blk)
|
|
50
47
|
else
|
|
51
|
-
|
|
48
|
+
Filter::Scoped.new(context.scoped_filter & arg, self)
|
|
52
49
|
end
|
|
53
50
|
end
|
|
54
51
|
|
|
55
52
|
protected
|
|
56
53
|
|
|
57
54
|
def _set_context(new_context)
|
|
58
|
-
@context =
|
|
55
|
+
@context = Filter::Scoped.new(new_context, self)
|
|
59
56
|
self
|
|
60
57
|
end
|
|
61
58
|
end
|
|
@@ -72,7 +69,7 @@ module Aws
|
|
|
72
69
|
# The method returns only the filter for the current class
|
|
73
70
|
# without consideration of the class hierarchy.
|
|
74
71
|
def module_context
|
|
75
|
-
@module_context ||=
|
|
72
|
+
@module_context ||= Filter::Identity.new
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
##
|
|
@@ -82,17 +79,11 @@ module Aws
|
|
|
82
79
|
# The method returns aggregate filter include module's own filters
|
|
83
80
|
# concatenated with all ancestor's filters.
|
|
84
81
|
def context
|
|
85
|
-
@context ||=
|
|
82
|
+
@context ||= ancestors_with(Contextualized).inject(Filter::Identity.new) do |acc, mod|
|
|
86
83
|
acc & mod.module_context
|
|
87
84
|
end
|
|
88
85
|
end
|
|
89
86
|
|
|
90
|
-
def _contextualized_ancestors
|
|
91
|
-
ancestors
|
|
92
|
-
.select { |mod| (mod != Contextualized) && mod.ancestors.include?(Contextualized) }
|
|
93
|
-
.reverse
|
|
94
|
-
end
|
|
95
|
-
|
|
96
87
|
##
|
|
97
88
|
# Add context filter
|
|
98
89
|
#
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
##
|
|
8
|
+
# Filter functor class
|
|
9
|
+
#
|
|
10
|
+
# A filter is a Proc accepting input hash and providing output
|
|
11
|
+
# hash which is expected to be a permutation of the input.
|
|
12
|
+
# The proc is executed in instance context so instance methods can
|
|
13
|
+
# be used for calculation.
|
|
14
|
+
#
|
|
15
|
+
# The class implements functor pattern through to_proc method and
|
|
16
|
+
# closure. Essentially, all filters can be used everywhere where
|
|
17
|
+
# a block is expected.
|
|
18
|
+
#
|
|
19
|
+
# It provides protected method filter which should be overriden in
|
|
20
|
+
# all concrete filter classes.
|
|
21
|
+
class Filter
|
|
22
|
+
using Contextualized::Refinements
|
|
23
|
+
##
|
|
24
|
+
# Chain filters
|
|
25
|
+
def &(other)
|
|
26
|
+
fltr = other.to_filter
|
|
27
|
+
return self if fltr.is_a?(Identity)
|
|
28
|
+
Chain.new(self, fltr)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
##
|
|
32
|
+
# Creates closure with filter invocation
|
|
33
|
+
#
|
|
34
|
+
# It's an interface method required for Filter to expose
|
|
35
|
+
# functor properties. It encloses invocation of Filter
|
|
36
|
+
# filter method into a closure. The closure itself is
|
|
37
|
+
# executed in the context of Filtered instance which provides
|
|
38
|
+
# proper set "self" variable.
|
|
39
|
+
#
|
|
40
|
+
# The closure itself accepts just one parameter:
|
|
41
|
+
# * +opts+ - input hash to be filtered
|
|
42
|
+
# ...where instance is assumed from self
|
|
43
|
+
def to_proc
|
|
44
|
+
fltr = self
|
|
45
|
+
->(opts, memo = {}) { fltr.filter(opts, memo, self) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# Filter method
|
|
50
|
+
#
|
|
51
|
+
# * +opts+ - input hash to be filtered
|
|
52
|
+
# * +instance+ - the instance filter is executed in
|
|
53
|
+
def filter(opts, memo, instance); end
|
|
54
|
+
|
|
55
|
+
def to_filter
|
|
56
|
+
self
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
class Filter
|
|
8
|
+
##
|
|
9
|
+
# Add specified keys into the hash
|
|
10
|
+
#
|
|
11
|
+
# Selective version of Copy filter. It adds key-value pairs or whole subtrees from
|
|
12
|
+
# options into the memo hash. It does this according to specified schema represented
|
|
13
|
+
# by combination of nested hashes and arrays. User can specify addition of values
|
|
14
|
+
# at arbitrary depth in options hash hierarchy with arbitrar granularity.
|
|
15
|
+
#
|
|
16
|
+
# === Example
|
|
17
|
+
#
|
|
18
|
+
# class Piece
|
|
19
|
+
# include Aws::Templates::Utils::Contextualized
|
|
20
|
+
#
|
|
21
|
+
# contextualize filter(:add, :a, :b, c: [:d])
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# i = Piece.new()
|
|
25
|
+
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
26
|
+
# opts.filter(i.filter) # => { a: { q: 1 }, b: 2, c: { d: { r: 5 } } }
|
|
27
|
+
class Add < RecursiveSchemaFilter
|
|
28
|
+
using Contextualized::Refinements
|
|
29
|
+
|
|
30
|
+
def filter(options, memo, _)
|
|
31
|
+
_recurse_add(options, memo, scheme)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def _recurse_add(opts, memo, schm)
|
|
37
|
+
return unless Utils.recursive?(opts)
|
|
38
|
+
|
|
39
|
+
if Utils.hashable?(schm)
|
|
40
|
+
_scheme_add(opts, memo, schm.to_hash)
|
|
41
|
+
elsif Utils.list?(schm)
|
|
42
|
+
_list_add(opts, memo, schm.to_ary)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
memo
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def _list_add(opts, memo, list)
|
|
49
|
+
list.each { |field| memo[field] = Utils.merge(memo[field], opts[field]) }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def _scheme_add(opts, memo, schm)
|
|
53
|
+
schm.each_pair do |field, sub_scheme|
|
|
54
|
+
next unless opts.include?(field)
|
|
55
|
+
memo[field] = if sub_scheme.nil?
|
|
56
|
+
Utils.merge(memo[field], opts[field])
|
|
57
|
+
else
|
|
58
|
+
_recurse_add(opts[field], memo[field] || {}, sub_scheme)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
class Filter
|
|
8
|
+
##
|
|
9
|
+
# Chain filters
|
|
10
|
+
#
|
|
11
|
+
# The filter chains all passed filters to have chained
|
|
12
|
+
# filter semantics.
|
|
13
|
+
#
|
|
14
|
+
# === Example
|
|
15
|
+
#
|
|
16
|
+
# class Piece
|
|
17
|
+
# include Aws::Templates::Utils::Contextualized
|
|
18
|
+
#
|
|
19
|
+
# contextualize filter(:copy) & filter(:remove, :c) & filter(:override, a: 12, b: 15)
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# i = Piece.new
|
|
23
|
+
# opts = Options.new(c: { e: 1 })
|
|
24
|
+
# opts.filter(i.filter) # => { a: 12, b: 15 }
|
|
25
|
+
class Chain < self
|
|
26
|
+
using Contextualized::Refinements
|
|
27
|
+
|
|
28
|
+
attr_reader :filters
|
|
29
|
+
|
|
30
|
+
def initialize(*flts)
|
|
31
|
+
wrong_objects = flts.reject { |f| f.respond_to?(:to_proc) }
|
|
32
|
+
unless wrong_objects.empty?
|
|
33
|
+
raise(
|
|
34
|
+
"The following objects are not filters: #{wrong_objects.inspect}"
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
@filters = flts.flat_map { |f| _as_flattened_filters(f) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def filter(options, memo, instance)
|
|
42
|
+
filters.inject(memo) { |acc, elem| instance.instance_exec(options, acc, &elem) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def _as_flattened_filters(flt)
|
|
48
|
+
return flt unless flt.is_a?(self.class)
|
|
49
|
+
flt.filters.flat_map { |obj| _as_flattened_filters(obj) }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
class Filter
|
|
8
|
+
##
|
|
9
|
+
# Add all options into the context
|
|
10
|
+
#
|
|
11
|
+
# The filter performs deep copy of entire options hash with consecutive merge into the
|
|
12
|
+
# resulting context
|
|
13
|
+
#
|
|
14
|
+
# === Example
|
|
15
|
+
#
|
|
16
|
+
# class Piece
|
|
17
|
+
# contextualize filter(:copy)
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# i = Piece.new()
|
|
21
|
+
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
22
|
+
# opts.filter(i.filter) # => { a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 } }
|
|
23
|
+
class Copy < self
|
|
24
|
+
using Contextualized::Refinements
|
|
25
|
+
|
|
26
|
+
PRE_FILTER = %i[label root parent meta].freeze
|
|
27
|
+
|
|
28
|
+
def filter(opts, memo, _)
|
|
29
|
+
result = Utils.deep_dup(opts.to_hash)
|
|
30
|
+
PRE_FILTER.each { |k| result.delete(k) }
|
|
31
|
+
Utils.merge(memo, result)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
require 'facets/string/modulize'
|
|
3
|
+
|
|
4
|
+
module Aws
|
|
5
|
+
module Templates
|
|
6
|
+
module Utils
|
|
7
|
+
module Contextualized
|
|
8
|
+
class Filter
|
|
9
|
+
##
|
|
10
|
+
# DSL for defining scope filters.
|
|
11
|
+
#
|
|
12
|
+
# The mixin adds DSL methods to both class context and instance context.
|
|
13
|
+
module Dsl
|
|
14
|
+
include Utils::Inheritable
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Mixin for filter factory method
|
|
18
|
+
#
|
|
19
|
+
# Adds filter factory method to the target
|
|
20
|
+
module FilterFactory
|
|
21
|
+
##
|
|
22
|
+
# Filter factory method
|
|
23
|
+
#
|
|
24
|
+
# It creates a filter based on type identifier and parameters with optional block
|
|
25
|
+
# which will be passed unchanged to the filter constructor.
|
|
26
|
+
# * +type+ - type identifier; can by either symbol or string
|
|
27
|
+
# * +args+ - filter constructor arguments
|
|
28
|
+
# * +blk+ - optional block to be passed to filter constructor
|
|
29
|
+
def filter(type, *args, &blk)
|
|
30
|
+
Filter.const_get(type.to_s.modulize).new(*args, &blk)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
# Class-level mixins
|
|
36
|
+
#
|
|
37
|
+
# It's a DSL extension to declaratively define context filters
|
|
38
|
+
class_scope do
|
|
39
|
+
include FilterFactory
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
instance_scope do
|
|
43
|
+
include FilterFactory
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
class Filter
|
|
8
|
+
##
|
|
9
|
+
# No-op filter
|
|
10
|
+
#
|
|
11
|
+
# No-op filter or identity filter doesn't perform any operations on passed options. The
|
|
12
|
+
# role of this filter is to play the role of identity function in par with lambda
|
|
13
|
+
# calculus.
|
|
14
|
+
#
|
|
15
|
+
# === Examples
|
|
16
|
+
#
|
|
17
|
+
# class Piece
|
|
18
|
+
# include Aws::Templates::Utils::Contextualized
|
|
19
|
+
#
|
|
20
|
+
# contextualize filter(:identity)
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# i = Piece.new
|
|
24
|
+
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
25
|
+
# opts.filter(i.filter) # => {}
|
|
26
|
+
class Identity < self
|
|
27
|
+
using Contextualized::Refinements
|
|
28
|
+
|
|
29
|
+
def self.new
|
|
30
|
+
@singleton ||= super()
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def filter(_, memo, _)
|
|
34
|
+
memo
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def &(other)
|
|
38
|
+
other.to_filter
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Contextualized
|
|
7
|
+
class Filter
|
|
8
|
+
##
|
|
9
|
+
# Override specified keys in options hash
|
|
10
|
+
#
|
|
11
|
+
# The filter performs merge the hash passed at initialization with
|
|
12
|
+
# options hash. Either hash itself or block returning a hash
|
|
13
|
+
# can be specified. The block will be evaluated in instance context
|
|
14
|
+
# so all instance methods are accessible.
|
|
15
|
+
#
|
|
16
|
+
# === Example
|
|
17
|
+
#
|
|
18
|
+
# class Piece
|
|
19
|
+
# include Aws::Templates::Utils::Contextualized
|
|
20
|
+
#
|
|
21
|
+
# contextualize filter(:copy) & filter(:override, a: 12, b: 15, c: { d: 30 })
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# i = Piece.new
|
|
25
|
+
# opts = Options.new(c: { e: 1 })
|
|
26
|
+
# opts.filter(i.filter) # => { a: 12, b: 15, c: { d: 30, e: 1 } }
|
|
27
|
+
class Override < self
|
|
28
|
+
using Contextualized::Refinements
|
|
29
|
+
|
|
30
|
+
attr_reader :override
|
|
31
|
+
|
|
32
|
+
def initialize(override = nil, &override_block)
|
|
33
|
+
@override = _check_override_type(override || override_block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def filter(_, memo, instance)
|
|
37
|
+
Utils.merge(
|
|
38
|
+
memo,
|
|
39
|
+
if override.respond_to?(:to_hash)
|
|
40
|
+
override
|
|
41
|
+
elsif override.respond_to?(:to_proc)
|
|
42
|
+
instance.instance_eval(&override)
|
|
43
|
+
end
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def _check_override_type(ovrr)
|
|
50
|
+
raise "Wrong override value: #{ovrr.inspect}" unless _proper_override_type?(ovrr)
|
|
51
|
+
ovrr
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def _proper_override_type?(ovrr)
|
|
55
|
+
ovrr.respond_to?(:to_hash) || ovrr.respond_to?(:to_proc)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|