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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Constraint
|
|
8
|
+
##
|
|
9
|
+
# Check if passed value is in the enumeration values.
|
|
10
|
+
#
|
|
11
|
+
# === Example
|
|
12
|
+
#
|
|
13
|
+
# class Piece
|
|
14
|
+
# include Aws::Templates::Utils::Parametrized
|
|
15
|
+
#
|
|
16
|
+
# parameter :param1, :constraint => enum([1,'2',3])
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# i = Piece.new(:param1 => 3)
|
|
20
|
+
# i.param1 # => 3
|
|
21
|
+
# i = Piece.new(:param1 => 4)
|
|
22
|
+
# i.param1 # throws ParameterValueInvalid
|
|
23
|
+
class Enum < self
|
|
24
|
+
attr_reader :set
|
|
25
|
+
|
|
26
|
+
def initialize(list)
|
|
27
|
+
@set = Set.new(list)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
protected
|
|
31
|
+
|
|
32
|
+
def check(_, value, _)
|
|
33
|
+
return if set.include?(value)
|
|
34
|
+
|
|
35
|
+
raise(
|
|
36
|
+
"Value #{value.inspect} is not in the set of allowed " \
|
|
37
|
+
"values #{set.inspect}"
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Constraint
|
|
8
|
+
##
|
|
9
|
+
# Check if value matches the regular expression
|
|
10
|
+
#
|
|
11
|
+
# Checks if value matches the regular expression. If value doesn't match, an exception
|
|
12
|
+
# will be thrown with attached description of regular expression and value converted to
|
|
13
|
+
# string.
|
|
14
|
+
#
|
|
15
|
+
# === Example
|
|
16
|
+
#
|
|
17
|
+
# class Piece
|
|
18
|
+
# include Aws::Templates::Utils::Parametrized
|
|
19
|
+
# parameter :param1, constraint: matches('A+')
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# i = Piece.new(:param1 => 'Ask')
|
|
23
|
+
# i.param1 # => 'Ask'
|
|
24
|
+
# i = Piece.new(:param1 => 'Bar')
|
|
25
|
+
# i.param1 # raise ParameterValueInvalid
|
|
26
|
+
class Matches < self
|
|
27
|
+
attr_reader :expression
|
|
28
|
+
|
|
29
|
+
def initialize(rex)
|
|
30
|
+
@expression = Regexp.new(rex)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def check(parameter, value, _)
|
|
36
|
+
return if expression =~ value.to_s
|
|
37
|
+
raise "#{value} doesn't match #{expression} for parameter #{parameter.name}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Constraint
|
|
8
|
+
##
|
|
9
|
+
# Check if passed value is not nil
|
|
10
|
+
#
|
|
11
|
+
# === Example
|
|
12
|
+
#
|
|
13
|
+
# class Piece
|
|
14
|
+
# include Aws::Templates::Utils::Parametrized
|
|
15
|
+
#
|
|
16
|
+
# parameter :param1, :constraint => not_nil
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# i = Piece.new(:param1 => 3)
|
|
20
|
+
# i.param1 # => 3
|
|
21
|
+
# i = Piece.new
|
|
22
|
+
# i.param1 # throws ParameterValueInvalid
|
|
23
|
+
class NotNil < self
|
|
24
|
+
def initialize
|
|
25
|
+
self.if(Constraint::Condition.any)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
def check(_, value, _)
|
|
31
|
+
raise('required but was not found in input hash') if value.nil?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Constraint
|
|
8
|
+
##
|
|
9
|
+
# Check presence of parameters if the condition is met
|
|
10
|
+
#
|
|
11
|
+
# Requires presence of the methods passed as dependencies in the
|
|
12
|
+
# current scope with non-nil returning values. Default condition
|
|
13
|
+
# for the value is not to be nil. The condition can be either
|
|
14
|
+
# a block or a value.
|
|
15
|
+
#
|
|
16
|
+
# === Example
|
|
17
|
+
#
|
|
18
|
+
# class Piece
|
|
19
|
+
# include Aws::Templates::Utils::Parametrized
|
|
20
|
+
# parameter :param2
|
|
21
|
+
# parameter :param1, :constraint => requires(:param2)
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# i = Piece.new(:param2 => 1)
|
|
25
|
+
# i.param1 # => nil
|
|
26
|
+
# i = Piece.new(:param1 => 1)
|
|
27
|
+
# i.param1 # raise ParameterValueInvalid
|
|
28
|
+
# i = Piece.new(:param1 => 2, :param2 => 1)
|
|
29
|
+
# i.param1 # => 2
|
|
30
|
+
class Requires < self
|
|
31
|
+
attr_reader :dependencies
|
|
32
|
+
|
|
33
|
+
def initialize(dependencies)
|
|
34
|
+
@dependencies = dependencies
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
protected
|
|
38
|
+
|
|
39
|
+
def check(parameter, value, instance)
|
|
40
|
+
dependencies.each do |pname|
|
|
41
|
+
next unless instance.send(pname).nil?
|
|
42
|
+
|
|
43
|
+
raise(
|
|
44
|
+
"#{pname} is required when #{parameter.name} value " \
|
|
45
|
+
"is set to #{value.inspect}"
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Constraint
|
|
8
|
+
##
|
|
9
|
+
# Check if value satisfies the condition
|
|
10
|
+
#
|
|
11
|
+
# Checks if value satisfies the condition defined in the block
|
|
12
|
+
# which should return true if the condition is met and false if it's
|
|
13
|
+
# not. If value fails the check, an exception will be thrown
|
|
14
|
+
# with attached condition description. The description is a part
|
|
15
|
+
# of constraint definition.
|
|
16
|
+
#
|
|
17
|
+
# The block is evaluated in the functor's invocation context.
|
|
18
|
+
#
|
|
19
|
+
# === Example
|
|
20
|
+
#
|
|
21
|
+
# class Piece
|
|
22
|
+
# include Aws::Templates::Utils::Parametrized
|
|
23
|
+
# parameter :param1,
|
|
24
|
+
# :constraint => satisfies('Mediocre value') { |v| v < 100 }
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# i = Piece.new(:param2 => 1)
|
|
28
|
+
# i.param1 # => 1
|
|
29
|
+
# i = Piece.new(:param1 => 101)
|
|
30
|
+
# i.param1 # raise ParameterValueInvalid
|
|
31
|
+
class SatisfiesCondition < self
|
|
32
|
+
attr_reader :condition
|
|
33
|
+
attr_reader :description
|
|
34
|
+
|
|
35
|
+
def initialize(description, &cond_block)
|
|
36
|
+
@condition = cond_block
|
|
37
|
+
@description = description
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
protected
|
|
41
|
+
|
|
42
|
+
def check(parameter, value, instance)
|
|
43
|
+
return if instance.instance_exec(value, &condition)
|
|
44
|
+
|
|
45
|
+
raise(
|
|
46
|
+
"#{value.inspect} doesn't satisfy the condition " \
|
|
47
|
+
"#{description} for parameter #{parameter.name}"
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
##
|
|
8
|
+
# Getter functor class
|
|
9
|
+
#
|
|
10
|
+
# A getter is a Proc without parameters and it is expected to return
|
|
11
|
+
# a value. Since the proc is to be executed in instance context
|
|
12
|
+
# the value can be calculated based on other methods or extracted from
|
|
13
|
+
# options attrribute
|
|
14
|
+
#
|
|
15
|
+
# The class implements functor pattern through to_proc method and
|
|
16
|
+
# closure. Essentially, all getters can be used everywhere where
|
|
17
|
+
# a block is expected.
|
|
18
|
+
#
|
|
19
|
+
# It provides protected method get which should be overriden in
|
|
20
|
+
# all concrete getter classes.
|
|
21
|
+
class Getter
|
|
22
|
+
##
|
|
23
|
+
# Creates closure with getter invocation
|
|
24
|
+
#
|
|
25
|
+
# It's an interface method required for Getter to expose
|
|
26
|
+
# functor properties. It encloses invocation of Getter get_wrapper
|
|
27
|
+
# method into a closure. The closure itself is executed in the context
|
|
28
|
+
# of Parametrized instance which provides proper set "self" variable.
|
|
29
|
+
#
|
|
30
|
+
# The closure itself accepts 1 parameters
|
|
31
|
+
# * +parameter+ - the Parameter object which the getter is executed for
|
|
32
|
+
# ...where instance is assumed from self
|
|
33
|
+
def to_proc
|
|
34
|
+
getter = self
|
|
35
|
+
|
|
36
|
+
lambda do |parameter|
|
|
37
|
+
getter.get_wrapper(parameter, self)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Wraps getter-dependent method
|
|
43
|
+
#
|
|
44
|
+
# It wraps constraint-dependent "get" method into a rescue block
|
|
45
|
+
# to standardize exception type and information provided by failed
|
|
46
|
+
# value calculation
|
|
47
|
+
# * +parameter+ - the Parameter object which the getter is executed for
|
|
48
|
+
# * +instance+ - the instance value is taken from
|
|
49
|
+
def get_wrapper(parameter, instance)
|
|
50
|
+
get(parameter, instance)
|
|
51
|
+
rescue StandardError
|
|
52
|
+
raise Templates::Exception::NestedParameterException.new(parameter)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
protected
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
# Getter method
|
|
59
|
+
#
|
|
60
|
+
# * +parameter+ - the Parameter object which the getter is executed for
|
|
61
|
+
# * +instance+ - the instance value is taken from
|
|
62
|
+
def get(parameter, instance); end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Getter
|
|
8
|
+
##
|
|
9
|
+
# Get parameter from instance variables as is
|
|
10
|
+
#
|
|
11
|
+
# Gets value from instance variable by parameter's name without
|
|
12
|
+
# any other operations performed.
|
|
13
|
+
#
|
|
14
|
+
# === Example
|
|
15
|
+
#
|
|
16
|
+
# class Piece
|
|
17
|
+
# include Aws::Templates::Utils::Parametrized
|
|
18
|
+
#
|
|
19
|
+
# parameter :param1, getter: as_instance_variable
|
|
20
|
+
#
|
|
21
|
+
# def initialize(x)
|
|
22
|
+
# @param1 = x
|
|
23
|
+
# end
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# i = Piece.new(3)
|
|
27
|
+
# i.param1 # => 3
|
|
28
|
+
class AsInstanceVariable < self
|
|
29
|
+
include ::Singleton
|
|
30
|
+
|
|
31
|
+
protected
|
|
32
|
+
|
|
33
|
+
def get(parameter, instance)
|
|
34
|
+
instance.instance_variable_get("@#{parameter.name}")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Getter
|
|
8
|
+
##
|
|
9
|
+
# Get options value "as is"
|
|
10
|
+
#
|
|
11
|
+
# Gets value from options attribute by parameter's name without
|
|
12
|
+
# any other operations performed.
|
|
13
|
+
#
|
|
14
|
+
# === Example
|
|
15
|
+
#
|
|
16
|
+
# class Piece
|
|
17
|
+
# include Aws::Templates::Utils::Parametrized
|
|
18
|
+
#
|
|
19
|
+
# parameter :param1, :getter => as_is
|
|
20
|
+
# end
|
|
21
|
+
#
|
|
22
|
+
# i = Piece.new(:param1 => 3)
|
|
23
|
+
# i.param1 # => 3
|
|
24
|
+
class AsIs < self
|
|
25
|
+
include ::Singleton
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
def get(parameter, instance)
|
|
30
|
+
instance.options[parameter.name]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'aws/templates/utils'
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Templates
|
|
5
|
+
module Utils
|
|
6
|
+
module Parametrized
|
|
7
|
+
class Getter
|
|
8
|
+
##
|
|
9
|
+
# Syntax sugar for getters definition
|
|
10
|
+
#
|
|
11
|
+
# It injects the methods as class-scope methods into mixing classes.
|
|
12
|
+
# The methods are factories to create particular type of getter
|
|
13
|
+
module Dsl
|
|
14
|
+
include Utils::Inheritable
|
|
15
|
+
|
|
16
|
+
class_scope do
|
|
17
|
+
##
|
|
18
|
+
# Get parameter from instance variables as is
|
|
19
|
+
#
|
|
20
|
+
# alias for AsInstanceVariable class
|
|
21
|
+
def as_instance_variable
|
|
22
|
+
Parametrized::Getter::AsInstanceVariable.instance
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
# Get parameter from Options as is
|
|
27
|
+
#
|
|
28
|
+
# alias for AsIs class
|
|
29
|
+
def as_is
|
|
30
|
+
Parametrized::Getter::AsIs.instance
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# Calculate value of parameter
|
|
35
|
+
#
|
|
36
|
+
# alias for Value class
|
|
37
|
+
def value(v = nil, &blk)
|
|
38
|
+
Parametrized::Getter::Value.new(v.nil? ? blk : v)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Look up value of the parameter with path
|
|
43
|
+
#
|
|
44
|
+
# alias for Path class
|
|
45
|
+
def path(*v, &blk)
|
|
46
|
+
Parametrized::Getter::Path.new(v.empty? ? blk : v)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
##
|
|
50
|
+
# Choose one non-nil value from nested getters
|
|
51
|
+
#
|
|
52
|
+
# alias for OneOf class
|
|
53
|
+
def one_of(*getters)
|
|
54
|
+
Parametrized::Getter::OneOf.new(getters)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|