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,13 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/utils/contextualized'
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Hash class patch
|
|
5
|
-
#
|
|
6
|
-
# Adds to_filter method converting a hash into an Override filter
|
|
7
|
-
class Hash
|
|
8
|
-
##
|
|
9
|
-
# Convert to Override filter
|
|
10
|
-
def to_filter
|
|
11
|
-
Aws::Templates::Utils::Contextualized::Filter::Override.new(self)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/utils/contextualized'
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# NilClass class patch
|
|
5
|
-
#
|
|
6
|
-
# Adds to_filter method converting nil into the Identity filter
|
|
7
|
-
class NilClass
|
|
8
|
-
##
|
|
9
|
-
# Convert nil to Identity filter
|
|
10
|
-
def to_filter
|
|
11
|
-
Aws::Templates::Utils::Contextualized::Filter::Identity.new
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/utils/contextualized'
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Proc class patch
|
|
5
|
-
#
|
|
6
|
-
# Adds to_filter method proxying a Proc through Filter interface object
|
|
7
|
-
class Proc
|
|
8
|
-
##
|
|
9
|
-
# Proxy the Proc through Proxy filter object
|
|
10
|
-
def to_filter
|
|
11
|
-
Aws::Templates::Utils::Contextualized::Filter::Proxy.new(self)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'set'
|
|
2
|
-
require 'aws/templates/utils/dependency'
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
# Dependency method stubs
|
|
6
|
-
#
|
|
7
|
-
# To avoid checking classes directly to filter out dependencies and non-dependencies, we're
|
|
8
|
-
# monkey-patching Object class with stubs for Dependency class.
|
|
9
|
-
#
|
|
10
|
-
# TODO: Devise a better approach and remove the extension
|
|
11
|
-
class Object
|
|
12
|
-
EMPTY_SET = Set.new.freeze
|
|
13
|
-
|
|
14
|
-
# By default an object is not a dependency
|
|
15
|
-
def dependency?
|
|
16
|
-
false
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# It returns self
|
|
20
|
-
def object
|
|
21
|
-
self
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
# Object root
|
|
26
|
-
#
|
|
27
|
-
# It is used to gracefully process dependencies
|
|
28
|
-
def root; end
|
|
29
|
-
|
|
30
|
-
alias not_a_dependency object
|
|
31
|
-
|
|
32
|
-
# it returns a set containing a single dependency on itself
|
|
33
|
-
def dependencies
|
|
34
|
-
EMPTY_SET
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# mark the object as dependency
|
|
38
|
-
def as_a_dependency
|
|
39
|
-
Aws::Templates::Utils::Dependency.new(object)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# mark the object as dependency of itself
|
|
43
|
-
def as_a_self_dependency
|
|
44
|
-
as_a_dependency.to_self
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/exceptions'
|
|
2
|
-
require 'aws/templates/utils/parametrized'
|
|
3
|
-
require 'set'
|
|
4
|
-
require 'singleton'
|
|
5
|
-
|
|
6
|
-
module Aws
|
|
7
|
-
module Templates
|
|
8
|
-
module Utils
|
|
9
|
-
module Parametrized #:nodoc:
|
|
10
|
-
##
|
|
11
|
-
# Constraint functor class
|
|
12
|
-
#
|
|
13
|
-
# A constraint is a Proc which accepts one parameter which is a value
|
|
14
|
-
# which needs to be checked and ir is expected to throw an exception
|
|
15
|
-
# if the value is not in compliance with the constraint
|
|
16
|
-
#
|
|
17
|
-
# The class implements functor pattern through to_proc method and
|
|
18
|
-
# closure. Essentially, all constraints can be used everywhere where
|
|
19
|
-
# a block is expected.
|
|
20
|
-
#
|
|
21
|
-
# It provides protected method check which should be overriden in
|
|
22
|
-
# all concrete constraint classes.
|
|
23
|
-
class Constraint
|
|
24
|
-
##
|
|
25
|
-
# Check if passed value is not nil
|
|
26
|
-
#
|
|
27
|
-
# === Example
|
|
28
|
-
#
|
|
29
|
-
# class Piece
|
|
30
|
-
# include Aws::Templates::Utils::Parametrized
|
|
31
|
-
#
|
|
32
|
-
# parameter :param1, :constraint => not_nil
|
|
33
|
-
# end
|
|
34
|
-
#
|
|
35
|
-
# i = Piece.new(:param1 => 3)
|
|
36
|
-
# i.param1 # => 3
|
|
37
|
-
# i = Piece.new
|
|
38
|
-
# i.param1 # throws ParameterValueInvalid
|
|
39
|
-
class NotNil < Constraint
|
|
40
|
-
include Singleton
|
|
41
|
-
|
|
42
|
-
protected
|
|
43
|
-
|
|
44
|
-
def check(_, value, _)
|
|
45
|
-
raise('required but was not found in input hash') if value.nil?
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
##
|
|
50
|
-
# Check if passed value is in the enumeration values.
|
|
51
|
-
#
|
|
52
|
-
# === Example
|
|
53
|
-
#
|
|
54
|
-
# class Piece
|
|
55
|
-
# include Aws::Templates::Utils::Parametrized
|
|
56
|
-
#
|
|
57
|
-
# parameter :param1, :constraint => enum([1,'2',3])
|
|
58
|
-
# end
|
|
59
|
-
#
|
|
60
|
-
# i = Piece.new(:param1 => 3)
|
|
61
|
-
# i.param1 # => 3
|
|
62
|
-
# i = Piece.new(:param1 => 4)
|
|
63
|
-
# i.param1 # throws ParameterValueInvalid
|
|
64
|
-
class Enum < Constraint
|
|
65
|
-
attr_reader :set
|
|
66
|
-
|
|
67
|
-
def initialize(list)
|
|
68
|
-
@set = Set.new(list)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
protected
|
|
72
|
-
|
|
73
|
-
def check(_, value, _)
|
|
74
|
-
return if value.nil? || set.include?(value)
|
|
75
|
-
|
|
76
|
-
raise(
|
|
77
|
-
"Value #{value.inspect} is not in the set of allowed " \
|
|
78
|
-
"values #{set.inspect}"
|
|
79
|
-
)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
# Switch-like variant check
|
|
85
|
-
#
|
|
86
|
-
# Recursive check implementing switch-based semantics for defining
|
|
87
|
-
# checks need to be performed depending on parameter's value.
|
|
88
|
-
#
|
|
89
|
-
# === Example
|
|
90
|
-
#
|
|
91
|
-
# class Piece
|
|
92
|
-
# include Aws::Templates::Utils::Parametrized
|
|
93
|
-
# parameter :param2
|
|
94
|
-
# parameter :param1,
|
|
95
|
-
# :constraint => depends_on_value(
|
|
96
|
-
# 1 => lambda { |v| raise 'Too big' if param2 > 3 },
|
|
97
|
-
# 2 => lambda { |v| raise 'Too small' if param2 < 2 }
|
|
98
|
-
# )
|
|
99
|
-
# end
|
|
100
|
-
#
|
|
101
|
-
# i = Piece.new(:param1 => 1, :param2 => 1)
|
|
102
|
-
# i.param1 # => 1
|
|
103
|
-
# i = Piece.new(:param1 => 1, :param2 => 5)
|
|
104
|
-
# i.param1 # raise ParameterValueInvalid
|
|
105
|
-
# i = Piece.new(:param1 => 2, :param2 => 1)
|
|
106
|
-
# i.param1 # raise ParameterValueInvalid
|
|
107
|
-
# i = Piece.new(:param1 => 2, :param2 => 5)
|
|
108
|
-
# i.param1 # => 2
|
|
109
|
-
class DependsOnValue < Constraint
|
|
110
|
-
##
|
|
111
|
-
# Selector hash
|
|
112
|
-
attr_reader :selector
|
|
113
|
-
|
|
114
|
-
def initialize(selector)
|
|
115
|
-
@selector = selector
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
protected
|
|
119
|
-
|
|
120
|
-
def check(parameter, value, instance)
|
|
121
|
-
return unless selector.key?(value)
|
|
122
|
-
|
|
123
|
-
instance.instance_exec(
|
|
124
|
-
parameter,
|
|
125
|
-
value,
|
|
126
|
-
&selector[value]
|
|
127
|
-
)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
##
|
|
132
|
-
# Check presence of parameters if the condition is met
|
|
133
|
-
#
|
|
134
|
-
# Requires presence of the methods passed as dependencies in the
|
|
135
|
-
# current scope with non-nil returning values. Default condition
|
|
136
|
-
# for the value is not to be nil. The condition can be either
|
|
137
|
-
# a block or a value.
|
|
138
|
-
#
|
|
139
|
-
# === Example
|
|
140
|
-
#
|
|
141
|
-
# class Piece
|
|
142
|
-
# include Aws::Templates::Utils::Parametrized
|
|
143
|
-
# parameter :param2
|
|
144
|
-
# parameter :param1, :constraint => requires(:param2)
|
|
145
|
-
# end
|
|
146
|
-
#
|
|
147
|
-
# i = Piece.new(:param2 => 1)
|
|
148
|
-
# i.param1 # => nil
|
|
149
|
-
# i = Piece.new(:param1 => 1)
|
|
150
|
-
# i.param1 # raise ParameterValueInvalid
|
|
151
|
-
# i = Piece.new(:param1 => 2, :param2 => 1)
|
|
152
|
-
# i.param1 # => 2
|
|
153
|
-
class Requires < Constraint
|
|
154
|
-
attr_reader :dependencies
|
|
155
|
-
attr_reader :condition
|
|
156
|
-
|
|
157
|
-
def initialize(dependencies)
|
|
158
|
-
@dependencies = dependencies
|
|
159
|
-
@condition = method(:not_nil?)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def if(*params, &blk)
|
|
163
|
-
if params.empty?
|
|
164
|
-
@condition = blk
|
|
165
|
-
else
|
|
166
|
-
test = params.first
|
|
167
|
-
@condition = ->(v) { v == test }
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
self
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
protected
|
|
174
|
-
|
|
175
|
-
def not_nil?(value)
|
|
176
|
-
!value.nil?
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def check(parameter, value, instance)
|
|
180
|
-
return unless instance.instance_exec(value, &condition)
|
|
181
|
-
|
|
182
|
-
dependencies.each do |pname|
|
|
183
|
-
next unless instance.send(pname).nil?
|
|
184
|
-
|
|
185
|
-
raise(
|
|
186
|
-
"#{pname} is required when #{parameter.name} value " \
|
|
187
|
-
"is set to #{value.inspect}"
|
|
188
|
-
)
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
##
|
|
194
|
-
# Check if value satisfies the condition
|
|
195
|
-
#
|
|
196
|
-
# Checks if value satisfies the condition defined in the block
|
|
197
|
-
# which should return true if the condition is met and false if it's
|
|
198
|
-
# not. If value fails the check, an exception will be thrown
|
|
199
|
-
# with attached condition description. The description is a part
|
|
200
|
-
# of constraint definition.
|
|
201
|
-
#
|
|
202
|
-
# The block is evaluated in the functor's invocation context.
|
|
203
|
-
#
|
|
204
|
-
# === Example
|
|
205
|
-
#
|
|
206
|
-
# class Piece
|
|
207
|
-
# include Aws::Templates::Utils::Parametrized
|
|
208
|
-
# parameter :param1,
|
|
209
|
-
# :constraint => satisfies('Mediocre value') { |v| v < 100 }
|
|
210
|
-
# end
|
|
211
|
-
#
|
|
212
|
-
# i = Piece.new(:param2 => 1)
|
|
213
|
-
# i.param1 # => 1
|
|
214
|
-
# i = Piece.new(:param1 => 101)
|
|
215
|
-
# i.param1 # raise ParameterValueInvalid
|
|
216
|
-
class SatisfiesCondition < Constraint
|
|
217
|
-
attr_reader :condition
|
|
218
|
-
attr_reader :description
|
|
219
|
-
|
|
220
|
-
def initialize(description, &cond_block)
|
|
221
|
-
@condition = cond_block
|
|
222
|
-
@description = description
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
protected
|
|
226
|
-
|
|
227
|
-
def check(parameter, value, instance)
|
|
228
|
-
return if value.nil? || instance.instance_exec(value, &condition)
|
|
229
|
-
|
|
230
|
-
raise(
|
|
231
|
-
"#{value.inspect} doesn't satisfy the condition " \
|
|
232
|
-
"#{description} for parameter #{parameter.name}"
|
|
233
|
-
)
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
##
|
|
238
|
-
# Check if value matches the regular expression
|
|
239
|
-
#
|
|
240
|
-
# Checks if value matches the regular expression. If value doesn't match, an exception
|
|
241
|
-
# will be thrown with attached description of regular expression and value converted to
|
|
242
|
-
# string.
|
|
243
|
-
#
|
|
244
|
-
# === Example
|
|
245
|
-
#
|
|
246
|
-
# class Piece
|
|
247
|
-
# include Aws::Templates::Utils::Parametrized
|
|
248
|
-
# parameter :param1, constraint: matches('A+')
|
|
249
|
-
# end
|
|
250
|
-
#
|
|
251
|
-
# i = Piece.new(:param1 => 'Ask')
|
|
252
|
-
# i.param1 # => 'Ask'
|
|
253
|
-
# i = Piece.new(:param1 => 'Bar')
|
|
254
|
-
# i.param1 # raise ParameterValueInvalid
|
|
255
|
-
class Matches < Constraint
|
|
256
|
-
attr_reader :expression
|
|
257
|
-
|
|
258
|
-
def initialize(rex)
|
|
259
|
-
@expression = Regexp.new(rex)
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
protected
|
|
263
|
-
|
|
264
|
-
def check(parameter, value, _)
|
|
265
|
-
return if value.nil? || (expression =~ value.to_s)
|
|
266
|
-
raise "#{value} doesn't match #{expression} for parameter #{parameter.name}"
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
##
|
|
271
|
-
# Aggregate constraint
|
|
272
|
-
#
|
|
273
|
-
# It is used to perform checks against a list of constraints-functors
|
|
274
|
-
# or lambdas.
|
|
275
|
-
#
|
|
276
|
-
# === Example
|
|
277
|
-
#
|
|
278
|
-
# class Piece
|
|
279
|
-
# include Aws::Templates::Utils::Parametrized
|
|
280
|
-
# parameter :param1,
|
|
281
|
-
# :constraint => all_of(
|
|
282
|
-
# not_nil,
|
|
283
|
-
# satisfies("Should be moderate") { |v| v < 100 }
|
|
284
|
-
# )
|
|
285
|
-
# end
|
|
286
|
-
#
|
|
287
|
-
# i = Piece.new(:param1 => nil)
|
|
288
|
-
# i.param1 # raise ParameterValueInvalid
|
|
289
|
-
# i = Piece.new(:param1 => 200)
|
|
290
|
-
# i.param1 # raise ParameterValueInvalid with description
|
|
291
|
-
# i = Piece.new(:param1 => 50)
|
|
292
|
-
# i.param1 # => 50
|
|
293
|
-
class AllOf < Constraint
|
|
294
|
-
attr_reader :constraints
|
|
295
|
-
|
|
296
|
-
def initialize(constraints)
|
|
297
|
-
@constraints = constraints
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
protected
|
|
301
|
-
|
|
302
|
-
def check(parameter, value, instance)
|
|
303
|
-
constraints.each do |c|
|
|
304
|
-
instance.instance_exec(parameter, value, &c)
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
##
|
|
310
|
-
# Creates closure with checker invocation
|
|
311
|
-
#
|
|
312
|
-
# It's an interface method required for Constraint to expose
|
|
313
|
-
# functor properties. It encloses invocation of Constraint check_wrapper
|
|
314
|
-
# method into a closure. The closure itself is executed in the context
|
|
315
|
-
# of Parametrized instance which provides proper set "self" variable.
|
|
316
|
-
#
|
|
317
|
-
# The closure itself accepts 2 parameters:
|
|
318
|
-
# * +parameter+ - the Parameter object which the constraint is evaluated
|
|
319
|
-
# against
|
|
320
|
-
# * +value+ - parameter value to be checked
|
|
321
|
-
# ...where instance is assumed from self
|
|
322
|
-
def to_proc
|
|
323
|
-
constraint = self
|
|
324
|
-
|
|
325
|
-
lambda do |parameter, value|
|
|
326
|
-
constraint.check_wrapper(parameter, value, self)
|
|
327
|
-
end
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
##
|
|
331
|
-
# Wraps constraint-dependent method
|
|
332
|
-
#
|
|
333
|
-
# It wraps constraint-dependent "check" method into a rescue block
|
|
334
|
-
# to standardize exception type and information provided by failed
|
|
335
|
-
# constraint validation
|
|
336
|
-
# * +parameter+ - the Parameter object which the constraint is evaluated
|
|
337
|
-
# against
|
|
338
|
-
# * +value+ - parameter value to be checked
|
|
339
|
-
# * +instance+ - the instance value is checked for
|
|
340
|
-
def check_wrapper(parameter, value, instance)
|
|
341
|
-
check(parameter, value, instance)
|
|
342
|
-
rescue StandardError
|
|
343
|
-
raise ParameterValueInvalid.new(parameter, instance, value)
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
protected
|
|
347
|
-
|
|
348
|
-
##
|
|
349
|
-
# Constraint-dependent check
|
|
350
|
-
#
|
|
351
|
-
# * +parameter+ - the Parameter object which the constraint is evaluated
|
|
352
|
-
# against
|
|
353
|
-
# * +value+ - parameter value to be checked
|
|
354
|
-
# * +instance+ - the instance value is checked for
|
|
355
|
-
def check(parameter, value, instance); end
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
##
|
|
359
|
-
# Syntax sugar for constraints definition
|
|
360
|
-
#
|
|
361
|
-
# It injects the methods as class-scope methods into mixing classes.
|
|
362
|
-
# The methods are factories to create particular type of constraint
|
|
363
|
-
class_scope do
|
|
364
|
-
##
|
|
365
|
-
# Parameter shouldn't be nil
|
|
366
|
-
#
|
|
367
|
-
# alias for NotNil class
|
|
368
|
-
def not_nil
|
|
369
|
-
Constraint::NotNil.instance
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
##
|
|
373
|
-
# Parameter value should be in enumeration
|
|
374
|
-
#
|
|
375
|
-
# alias for Enum class
|
|
376
|
-
def enum(*items)
|
|
377
|
-
Constraint::Enum.new(items.flatten)
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
##
|
|
381
|
-
# Parameter value should satisfy all specified constraints
|
|
382
|
-
#
|
|
383
|
-
# alias for AllOf class
|
|
384
|
-
def all_of(*constraints)
|
|
385
|
-
Constraint::AllOf.new(constraints)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
##
|
|
389
|
-
# Requires presence of the parameters if condition is satisfied
|
|
390
|
-
#
|
|
391
|
-
# alias for Requires class
|
|
392
|
-
def requires(*dependencies)
|
|
393
|
-
Constraint::Requires.new(dependencies)
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
##
|
|
397
|
-
# Constraint depends on value
|
|
398
|
-
#
|
|
399
|
-
# alias for DependsOnValue class
|
|
400
|
-
def depends_on_value(selector)
|
|
401
|
-
Constraint::DependsOnValue.new(selector)
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
##
|
|
405
|
-
# Constraint should satisfy the condition
|
|
406
|
-
#
|
|
407
|
-
# alias for SatisfiesCondition class
|
|
408
|
-
def satisfies(description, &cond_block)
|
|
409
|
-
Constraint::SatisfiesCondition.new(description, &cond_block)
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
##
|
|
413
|
-
# Value should match the regular experession
|
|
414
|
-
#
|
|
415
|
-
# alias for Matches
|
|
416
|
-
def matches(rex)
|
|
417
|
-
Constraint::Matches.new(rex)
|
|
418
|
-
end
|
|
419
|
-
end
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
end
|
|
423
|
-
end
|