cloud-templates 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/render'
|
2
|
-
require 'aws/templates/render/view'
|
3
1
|
require 'aws/templates/utils'
|
4
|
-
require 'aws/templates/utils/dependency'
|
5
|
-
require 'aws/templates/utils/options'
|
6
2
|
|
7
3
|
module Aws
|
8
4
|
module Templates
|
@@ -15,10 +11,11 @@ module Aws
|
|
15
11
|
# specific types.
|
16
12
|
module BaseTypeViews
|
17
13
|
include Render
|
14
|
+
using Templates::Utils::Dependency::Refinements
|
18
15
|
|
19
16
|
##
|
20
17
|
# Pass-through render
|
21
|
-
class AsIs < BasicView
|
18
|
+
class AsIs < Render::BasicView
|
22
19
|
def to_rendered
|
23
20
|
instance.object
|
24
21
|
end
|
@@ -26,7 +23,7 @@ module Aws
|
|
26
23
|
|
27
24
|
##
|
28
25
|
# Convert to string
|
29
|
-
class ToString < BasicView
|
26
|
+
class ToString < Render::BasicView
|
30
27
|
def to_rendered
|
31
28
|
instance.to_s
|
32
29
|
end
|
@@ -36,11 +33,11 @@ module Aws
|
|
36
33
|
# Convert to array
|
37
34
|
#
|
38
35
|
# Converts value to array and iteratively renders every element in it.
|
39
|
-
class ToArray < BasicView
|
36
|
+
class ToArray < Render::BasicView
|
40
37
|
def to_rendered
|
41
38
|
instance
|
42
39
|
.to_a
|
43
|
-
.map { |element|
|
40
|
+
.map { |element| processed_for(element) }
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
@@ -48,9 +45,9 @@ module Aws
|
|
48
45
|
# Convert to hash
|
49
46
|
#
|
50
47
|
# Converts value to hash and iteratively renders each key and value in it.
|
51
|
-
class ToHash < BasicView
|
48
|
+
class ToHash < Render::BasicView
|
52
49
|
def to_rendered
|
53
|
-
_from(instance).map { |k, v| [
|
50
|
+
_from(instance).map { |k, v| [processed_for(k), processed_for(v)] }.to_h
|
54
51
|
end
|
55
52
|
|
56
53
|
private
|
@@ -62,15 +59,11 @@ module Aws
|
|
62
59
|
instance.to_hash
|
63
60
|
end
|
64
61
|
end
|
65
|
-
|
66
|
-
def _to_rendered(obj)
|
67
|
-
render.view_for(obj, parameters).to_rendered
|
68
|
-
end
|
69
62
|
end
|
70
63
|
|
71
64
|
##
|
72
65
|
# Convert to float
|
73
|
-
class ToFloat < BasicView
|
66
|
+
class ToFloat < Render::BasicView
|
74
67
|
def to_rendered
|
75
68
|
instance.to_f
|
76
69
|
end
|
@@ -78,7 +71,7 @@ module Aws
|
|
78
71
|
|
79
72
|
##
|
80
73
|
# Convert to integer
|
81
|
-
class ToInteger < BasicView
|
74
|
+
class ToInteger < Render::BasicView
|
82
75
|
def to_rendered
|
83
76
|
instance.to_i
|
84
77
|
end
|
@@ -86,7 +79,7 @@ module Aws
|
|
86
79
|
|
87
80
|
##
|
88
81
|
# Convert to boolean
|
89
|
-
class ToBoolean < BasicView
|
82
|
+
class ToBoolean < Render::BasicView
|
90
83
|
def to_rendered
|
91
84
|
!instance.to_s.casecmp('false').zero?
|
92
85
|
end
|
@@ -100,10 +93,10 @@ module Aws
|
|
100
93
|
::FalseClass => AsIs,
|
101
94
|
::NilClass => AsIs,
|
102
95
|
::Symbol => AsIs,
|
103
|
-
Templates::Utils::Dependency => AsIs,
|
96
|
+
Aws::Templates::Utils::Dependency => AsIs,
|
104
97
|
::Array => ToArray,
|
105
98
|
::Hash => ToHash,
|
106
|
-
Templates::Utils::Options => ToHash
|
99
|
+
Aws::Templates::Utils::Options => ToHash
|
107
100
|
}.freeze
|
108
101
|
|
109
102
|
##
|
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'aws/templates/
|
2
|
-
require 'aws/templates/utils/parametrized'
|
3
|
-
require 'aws/templates/utils/dependency'
|
1
|
+
require 'aws/templates/utils'
|
4
2
|
|
5
3
|
module Aws
|
6
4
|
module Templates
|
@@ -29,7 +27,7 @@ module Aws
|
|
29
27
|
#
|
30
28
|
# Defines "depth" property which is used to control recursion depth during object
|
31
29
|
# introspection.
|
32
|
-
class InspectView < BasicView
|
30
|
+
class InspectView < Render::BasicView
|
33
31
|
def depth
|
34
32
|
(parameters.nil? ? Inspect.recursion_depth : Integer(parameters)) - 1
|
35
33
|
end
|
@@ -1,7 +1,4 @@
|
|
1
|
-
require 'aws/templates/
|
2
|
-
require 'aws/templates/artifact'
|
3
|
-
require 'aws/templates/utils/parametrized/nested'
|
4
|
-
require 'aws/templates/utils/dependency'
|
1
|
+
require 'aws/templates/utils'
|
5
2
|
|
6
3
|
module Aws
|
7
4
|
module Templates
|
@@ -17,7 +14,7 @@ module Aws
|
|
17
14
|
|
18
15
|
define_view(::Object) do
|
19
16
|
def to_rendered
|
20
|
-
instance.
|
17
|
+
instance.class.name
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
@@ -1,112 +1,15 @@
|
|
1
|
+
require 'aws/templates/utils'
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Templates
|
3
5
|
module Render
|
4
|
-
##
|
5
|
-
# Basic render view
|
6
|
-
#
|
7
|
-
# Views are classes encapsulating functionality of transforming
|
8
|
-
# artifacts into domain-specific output. For instance, the same
|
9
|
-
# LDAP record can be transformed into JSON description or LDIF definition.
|
10
|
-
# Views can be attached to ancestors of an artifact and it expected
|
11
|
-
# that the library will look-up the closest ancestor having view attached
|
12
|
-
# if the render is invoked on a child.
|
13
|
-
#
|
14
|
-
# Each view is attached to a registry object which stores correspondence
|
15
|
-
# between artifact classes and their views, and optionally to an artifact.
|
16
|
-
# A view is registered in a registry only when it is attached to an artifact.
|
17
|
-
# Views depend on artifacts but artifacts are not aware of views.
|
18
|
-
# As the extreme case, a sole view can be attached to Artifact
|
19
|
-
# if you have universal way to render your domain objects.
|
20
|
-
#
|
21
|
-
# Views are regular Ruby classes and all assumptions made about
|
22
|
-
# polymorphism, inheritance and incapsulation are true for them.
|
23
|
-
#
|
24
|
-
# View class itself is an abstract class which can't be instantiated
|
25
|
-
# directly.
|
26
|
-
class BasicView
|
27
|
-
##
|
28
|
-
# Render accessor
|
29
|
-
#
|
30
|
-
# Returns either render of this view class or render of any ancestor.
|
31
|
-
def self.render
|
32
|
-
@render || superclass.render
|
33
|
-
end
|
34
|
-
|
35
|
-
##
|
36
|
-
# Register the view class in a render
|
37
|
-
#
|
38
|
-
# Registers the view class in the render
|
39
|
-
# * +r+ - render registrar
|
40
|
-
def self.register_in(r)
|
41
|
-
@render = r
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
# Link the view class to the artifact class
|
47
|
-
#
|
48
|
-
# Registers the link in the render object of the view class.
|
49
|
-
def self.artifact(artifact_class)
|
50
|
-
render.register(artifact_class, self)
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
##
|
55
|
-
# Artifact instance view object is attached to
|
56
|
-
attr_reader :instance
|
57
|
-
|
58
|
-
##
|
59
|
-
# Assigned view parameters
|
60
|
-
attr_reader :parameters
|
61
|
-
|
62
|
-
##
|
63
|
-
# Execute in the instance context
|
64
|
-
#
|
65
|
-
# Executed passed block in the context of the instance being rendered. It helps against
|
66
|
-
# putting too much instance method accesses in long blocks. Returns the value returned by
|
67
|
-
# the block.
|
68
|
-
def in_instance(*args, &blk)
|
69
|
-
instance.instance_exec(*args, &blk)
|
70
|
-
end
|
71
|
-
|
72
|
-
##
|
73
|
-
# Create view instance and link it to the artifact instance
|
74
|
-
def initialize(obj, params = nil)
|
75
|
-
@instance = obj
|
76
|
-
@parameters = params
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# Alias for class method render
|
81
|
-
def render
|
82
|
-
self.class.render
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# Render the object
|
87
|
-
#
|
88
|
-
# Renders passed object with the view default render
|
89
|
-
def rendered_for(obj, parameters_override = nil)
|
90
|
-
render.view_for(obj, parameters_override.nil? ? parameters : parameters_override)
|
91
|
-
.to_rendered
|
92
|
-
end
|
93
|
-
|
94
|
-
##
|
95
|
-
# Render the instance of the artifact
|
96
|
-
#
|
97
|
-
# The method should be overriden and return rendered form of the attached instance
|
98
|
-
def to_rendered
|
99
|
-
raise NotImplementedError.new('The method should be overriden')
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
6
|
##
|
104
7
|
# Render view
|
105
8
|
#
|
106
9
|
# The class introduces additional stage called "prepare" where you can put prepared view
|
107
10
|
# which will be additionally recursively rendered. Useful for complex views containing values
|
108
11
|
# needed additional rendering so you don't need to invoke rendered_for.
|
109
|
-
class View < BasicView
|
12
|
+
class View < Render::BasicView
|
110
13
|
##
|
111
14
|
# Render the instance of the artifact
|
112
15
|
#
|
data/lib/aws/templates/utils.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
|
-
require 'aws/templates/
|
1
|
+
require 'aws/templates/utils/autoload'
|
2
|
+
require 'facets/string/modulize'
|
2
3
|
|
3
4
|
##
|
4
|
-
#
|
5
|
-
class
|
6
|
-
|
7
|
-
|
5
|
+
# Utility methods for Module class
|
6
|
+
class Module
|
7
|
+
##
|
8
|
+
# Get all ancestors which have "base" module as one of its' own ancestors
|
9
|
+
def ancestors_with(base)
|
10
|
+
ancestors.reverse_each.select { |mod| mod < base }
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
14
|
module Aws
|
12
15
|
module Templates
|
13
16
|
##
|
14
|
-
# Variable utility functions used through the code
|
17
|
+
# Variable utility functions used through the code.
|
18
|
+
#
|
19
|
+
# Defines auxiliary functions set and serves as the namespace for the framework modules.
|
15
20
|
module Utils
|
21
|
+
include Templates::Exception
|
22
|
+
|
16
23
|
RECURSIVE_METHODS = %i[keys [] include?].freeze
|
17
24
|
|
18
25
|
##
|
@@ -95,19 +102,24 @@ module Aws
|
|
95
102
|
##
|
96
103
|
# Recursively merge two "recursive" objects
|
97
104
|
# PS: Yes I know that there is "merge" method for *hashes*.
|
98
|
-
def self.merge(a, b)
|
99
|
-
|
100
|
-
|
105
|
+
def self.merge(a, b, &blk)
|
106
|
+
unless Utils.recursive?(a) && Utils.recursive?(b)
|
107
|
+
return hashify(blk.nil? ? b : blk.call(a, b))
|
108
|
+
end
|
109
|
+
|
110
|
+
_merge_back(_merge_forward(a, b, blk), b)
|
101
111
|
end
|
102
112
|
|
103
|
-
def self._merge_forward(a, b)
|
113
|
+
def self._merge_forward(a, b, blk)
|
104
114
|
a.keys.each_with_object({}) do |k, hsh|
|
105
|
-
hsh[k] = b[k].nil? ? hashify(a[k]) : merge(a[k], b[k])
|
115
|
+
hsh[k] = b[k].nil? ? hashify(a[k]) : merge(a[k], b[k], &blk)
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
109
119
|
def self._merge_back(result, b)
|
110
|
-
b.keys
|
120
|
+
b.keys
|
121
|
+
.reject { |k| result.include?(k) }
|
122
|
+
.each_with_object(result) { |k, res| res[k] = hashify(b[k]) }
|
111
123
|
end
|
112
124
|
|
113
125
|
def self.hashify(v)
|
@@ -157,11 +169,11 @@ module Aws
|
|
157
169
|
# we stop lookup and return nil if nil is encountered
|
158
170
|
return if value.nil?
|
159
171
|
# value was deleted in this layer
|
160
|
-
raise OptionValueDeleted.new(path) if value == DELETED_MARKER
|
172
|
+
raise Exception::OptionValueDeleted.new(path) if value == DELETED_MARKER
|
161
173
|
# we reached our target! returning it
|
162
174
|
return value if path.nil? || path.empty?
|
163
175
|
# we still have some part of path to traverse but scalar was found
|
164
|
-
raise OptionScalarOnTheWay.new(value, path) if Utils.scalar?(value)
|
176
|
+
raise Exception::OptionScalarOnTheWay.new(value, path) if Utils.scalar?(value)
|
165
177
|
|
166
178
|
_lookup_recursively(value, path.dup)
|
167
179
|
end
|
@@ -194,7 +206,7 @@ module Aws
|
|
194
206
|
last_key = path.pop
|
195
207
|
|
196
208
|
last_branch = path.inject(container) do |obj, current_key|
|
197
|
-
raise OptionScalarOnTheWay.new(obj, path) unless Utils.recursive?(obj)
|
209
|
+
raise Exception::OptionScalarOnTheWay.new(obj, path) unless Utils.recursive?(obj)
|
198
210
|
if obj.include?(current_key)
|
199
211
|
obj[current_key]
|
200
212
|
else
|
@@ -222,6 +234,18 @@ module Aws
|
|
222
234
|
end
|
223
235
|
end
|
224
236
|
end
|
237
|
+
|
238
|
+
PATH_REGEXP = Regexp.compile('::|[.]|/')
|
239
|
+
|
240
|
+
def self.lookup_module(str)
|
241
|
+
target = str.split(PATH_REGEXP)
|
242
|
+
.inject(::Object.lazy) { |acc, elem| acc.const_get(elem.modulize) }
|
243
|
+
.reduce
|
244
|
+
|
245
|
+
raise "#{str} == #{target} which is not a module" unless target.is_a?(Module)
|
246
|
+
|
247
|
+
target
|
248
|
+
end
|
225
249
|
end
|
226
250
|
end
|
227
251
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'aws/templates/
|
2
|
-
require 'set'
|
1
|
+
require 'aws/templates/utils'
|
3
2
|
|
4
3
|
module Aws
|
5
4
|
module Templates
|
@@ -100,7 +99,7 @@ module Aws
|
|
100
99
|
|
101
100
|
def initialize
|
102
101
|
@map = {}
|
103
|
-
@set = Set.new
|
102
|
+
@set = ::Set.new
|
104
103
|
end
|
105
104
|
|
106
105
|
private
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'aws/templates/utils
|
2
|
-
require 'aws/templates/utils/parametrized/constraints'
|
1
|
+
require 'aws/templates/utils'
|
3
2
|
|
4
3
|
module Aws
|
5
4
|
module Templates
|
@@ -10,7 +9,7 @@ module Aws
|
|
10
9
|
# Provides a simple utility to define artifacts/objects which have
|
11
10
|
# "name" parameter which should be present as :name in the input hash
|
12
11
|
module AsNamed
|
13
|
-
include Parametrized
|
12
|
+
include Aws::Templates::Utils::Parametrized
|
14
13
|
|
15
14
|
parameter :name, description: 'Name of the object', constraint: not_nil
|
16
15
|
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
require 'facets/string/pathize'
|
2
|
+
require 'facets/module/pathize'
|
3
|
+
require 'set'
|
4
|
+
require 'concurrent/map'
|
5
|
+
|
6
|
+
module Aws
|
7
|
+
module Templates
|
8
|
+
module Utils
|
9
|
+
##
|
10
|
+
# Lazy load implementation
|
11
|
+
#
|
12
|
+
# It allows to skip 'require' definitions and load all classes and modules by convention.
|
13
|
+
module Autoload
|
14
|
+
REQUIRE_LOCKER = Concurrent::Map.new
|
15
|
+
MODULE_LOCKER = Concurrent::Map.new
|
16
|
+
|
17
|
+
Trace = TracePoint.new(:class) { |tp| Autoload.autoload!(tp.self) }
|
18
|
+
|
19
|
+
def self._try_to_require(path, mutex)
|
20
|
+
require path
|
21
|
+
rescue ScriptError, NoMemoryError, StandardError => e
|
22
|
+
REQUIRE_LOCKER.get_and_set(path, e)
|
23
|
+
raise e
|
24
|
+
ensure
|
25
|
+
mutex.unlock
|
26
|
+
end
|
27
|
+
|
28
|
+
def self._check_if_required(path, obj)
|
29
|
+
raise(obj) if obj.is_a?(::Exception)
|
30
|
+
return if obj.owned?
|
31
|
+
|
32
|
+
obj.lock.unlock
|
33
|
+
locker_obj = REQUIRE_LOCKER[path]
|
34
|
+
raise locker_obj if locker_obj.is_a?(Exception)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.atomic_require(path)
|
38
|
+
mutex = Mutex.new.lock
|
39
|
+
|
40
|
+
obj = REQUIRE_LOCKER.put_if_absent(path, mutex)
|
41
|
+
|
42
|
+
if obj.nil?
|
43
|
+
_try_to_require(path, mutex)
|
44
|
+
else
|
45
|
+
_check_if_required(path, obj)
|
46
|
+
end
|
47
|
+
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.autoload!(mod)
|
52
|
+
return if mod.name.nil?
|
53
|
+
|
54
|
+
MODULE_LOCKER.compute_if_absent(mod) do
|
55
|
+
path = mod.pathize
|
56
|
+
|
57
|
+
begin
|
58
|
+
atomic_require path
|
59
|
+
rescue LoadError => e
|
60
|
+
sanitize_load_exception(e, path)
|
61
|
+
end
|
62
|
+
|
63
|
+
true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.const_path_for(mod, const_name)
|
68
|
+
raise ScriptError.new("Autoload is not supported for #{mod}") if mod.name.nil?
|
69
|
+
|
70
|
+
path = const_name.to_s.pathize
|
71
|
+
|
72
|
+
path = "#{mod.pathize}/#{path}" unless mod.root_namespace?
|
73
|
+
|
74
|
+
path
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.sanitize_load_exception(e, path)
|
78
|
+
raise e unless e.path == path
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.const_is_loaded?(mod, const_name)
|
82
|
+
const_path = Autoload.const_path_for(mod, const_name)
|
83
|
+
|
84
|
+
begin
|
85
|
+
atomic_require const_path
|
86
|
+
true
|
87
|
+
rescue LoadError => e
|
88
|
+
Autoload.sanitize_load_exception(e, const_path)
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def const_missing(const_name)
|
94
|
+
super(const_name) unless Autoload.const_is_loaded?(self, const_name)
|
95
|
+
|
96
|
+
unless const_defined?(const_name)
|
97
|
+
raise NameError.new(
|
98
|
+
"::#{self}::#{const_name} is loaded but the constant is missing"
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
const_get(const_name)
|
103
|
+
end
|
104
|
+
|
105
|
+
def lazy
|
106
|
+
Lazy.new(self)
|
107
|
+
end
|
108
|
+
|
109
|
+
def reduce(_ = false)
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def root_namespace?
|
114
|
+
(self == ::Kernel) || (self == ::Object)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Lazy module wrapper
|
120
|
+
#
|
121
|
+
# Allows to traverse non-existent modules up to the point when constant can be
|
122
|
+
# auto-discovered.
|
123
|
+
class Lazy < Module
|
124
|
+
def self.fail_on_method(method_name)
|
125
|
+
define_method(method_name) { |*params, &blk| raise_error(method_name, params, blk) }
|
126
|
+
end
|
127
|
+
|
128
|
+
def raise_error(method_name, params, blk)
|
129
|
+
raise NoMethodError.new(
|
130
|
+
"Lazy namespace #{self} doesn't support #{method_name}\n" \
|
131
|
+
" Parameters: #{params}\n" \
|
132
|
+
" Block: #{blk}"
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
fail_on_method :alias_method
|
137
|
+
fail_on_method :append_features
|
138
|
+
fail_on_method :attr
|
139
|
+
fail_on_method :attr_accessor
|
140
|
+
fail_on_method :attr_reader
|
141
|
+
fail_on_method :attr_writer
|
142
|
+
fail_on_method :autoload
|
143
|
+
fail_on_method :autoload?
|
144
|
+
fail_on_method :define_method
|
145
|
+
fail_on_method :extend_object
|
146
|
+
fail_on_method :extended
|
147
|
+
fail_on_method :include
|
148
|
+
fail_on_method :included
|
149
|
+
fail_on_method :method_added
|
150
|
+
fail_on_method :method_removed
|
151
|
+
fail_on_method :method_undefined
|
152
|
+
fail_on_method :prepend
|
153
|
+
fail_on_method :prepend_features
|
154
|
+
fail_on_method :prepended
|
155
|
+
fail_on_method :refine
|
156
|
+
fail_on_method :remove_method
|
157
|
+
fail_on_method :undef_method
|
158
|
+
fail_on_method :using
|
159
|
+
|
160
|
+
def method_missing(method_name, *params, &blk)
|
161
|
+
raise_error(method_name, params, blk)
|
162
|
+
super
|
163
|
+
end
|
164
|
+
|
165
|
+
def respond_to_missing?(*)
|
166
|
+
super
|
167
|
+
end
|
168
|
+
|
169
|
+
def const_missing(const_name)
|
170
|
+
Lazy.new(self, const_name)
|
171
|
+
end
|
172
|
+
|
173
|
+
def reduce(is_loaded = false)
|
174
|
+
return @parent.reduce if @short_name.nil?
|
175
|
+
|
176
|
+
@parent.reduce(is_loaded || Autoload.const_is_loaded?(@parent, @short_name))
|
177
|
+
.const_get(@short_name)
|
178
|
+
end
|
179
|
+
|
180
|
+
def to_s
|
181
|
+
name
|
182
|
+
end
|
183
|
+
|
184
|
+
def inspect
|
185
|
+
"#{name}(Lazy)"
|
186
|
+
end
|
187
|
+
|
188
|
+
def lazy
|
189
|
+
self
|
190
|
+
end
|
191
|
+
|
192
|
+
def name
|
193
|
+
return @parent.name if @short_name.nil?
|
194
|
+
|
195
|
+
if @parent.root_namespace?
|
196
|
+
@short_name.to_s
|
197
|
+
else
|
198
|
+
"#{@parent.name}::#{@short_name}"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def root_namespace?
|
203
|
+
@parent.root_namespace? && @short_name.nil?
|
204
|
+
end
|
205
|
+
|
206
|
+
def initialize(parent, short_name = nil)
|
207
|
+
raise ScriptError.new("#{parent} is not a module") unless parent.is_a?(Module)
|
208
|
+
@parent = parent
|
209
|
+
@short_name = short_name
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# Lazy load
|
218
|
+
#
|
219
|
+
# It allows to skip 'require' definitions and load all classes and modules by convention.
|
220
|
+
class Module
|
221
|
+
prepend Aws::Templates::Utils::Autoload
|
222
|
+
end
|
223
|
+
|
224
|
+
Aws::Templates::Utils::Autoload::Trace.enable
|