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,221 +0,0 @@
|
|
|
1
|
-
module Aws
|
|
2
|
-
module Templates
|
|
3
|
-
##
|
|
4
|
-
# Parameter definition exception
|
|
5
|
-
#
|
|
6
|
-
# Meta-programming exception related to Parametrized DSL
|
|
7
|
-
class ParametrizedDSLError < StandardError
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
##
|
|
11
|
-
# Parameter already exists
|
|
12
|
-
#
|
|
13
|
-
# If you're trying to define a parameter in a parametrized artifact
|
|
14
|
-
# and this parameter either already defined for the class or defined
|
|
15
|
-
# in an ancestor.
|
|
16
|
-
class ParameterAlreadyExist < ParametrizedDSLError
|
|
17
|
-
# Parameter object of the conflicting parameter
|
|
18
|
-
attr_reader :parameter
|
|
19
|
-
|
|
20
|
-
def initialize(target_parameter)
|
|
21
|
-
@parameter = target_parameter
|
|
22
|
-
super(
|
|
23
|
-
"Parameter #{target_parameter.name} already in " \
|
|
24
|
-
"#{target_parameter.klass}."
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
##
|
|
30
|
-
# Invalid parameter specification hash
|
|
31
|
-
#
|
|
32
|
-
# If unknown option is passed in a parameter description block
|
|
33
|
-
class ParameterSpecificationIsInvalid < ParametrizedDSLError
|
|
34
|
-
# Parameter object faulty options were specified for
|
|
35
|
-
attr_reader :parameter
|
|
36
|
-
|
|
37
|
-
# Options unknown to Parametrized
|
|
38
|
-
attr_reader :options
|
|
39
|
-
|
|
40
|
-
def initialize(target_parameter, opts)
|
|
41
|
-
@parameter = target_parameter
|
|
42
|
-
@options = opts
|
|
43
|
-
|
|
44
|
-
super(
|
|
45
|
-
'Unsupported options are in specification for ' \
|
|
46
|
-
"parameter #{target_parameter.name} in class " \
|
|
47
|
-
"#{target_parameter.klass} : #{opts}"
|
|
48
|
-
)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
##
|
|
53
|
-
# A regular method and a parameter have the same name in a class
|
|
54
|
-
#
|
|
55
|
-
# A parameter was specified with the same name as exsiting method
|
|
56
|
-
# in the class or in an ancestor of the class.
|
|
57
|
-
class ParameterMethodNameConflict < ParametrizedDSLError
|
|
58
|
-
# Method object of the method specified
|
|
59
|
-
attr_reader :method_object
|
|
60
|
-
|
|
61
|
-
def initialize(target_method)
|
|
62
|
-
@method_object = target_method
|
|
63
|
-
|
|
64
|
-
super(
|
|
65
|
-
"Parameter name #{target_method.name} clashes with a method name in " \
|
|
66
|
-
"#{target_method.owner.name}"
|
|
67
|
-
)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
# View was not found for the object
|
|
73
|
-
#
|
|
74
|
-
# View map was checked and there is no appropriate view class
|
|
75
|
-
# for the object class found in the registry.
|
|
76
|
-
class ViewNotFound < RuntimeError
|
|
77
|
-
# Instance of the object class render lookup was performed for
|
|
78
|
-
attr_reader :instance
|
|
79
|
-
|
|
80
|
-
def message
|
|
81
|
-
"Can't find any view for #{instance} of class #{instance.class}"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def initialize(target_instance)
|
|
85
|
-
super()
|
|
86
|
-
@instance = target_instance
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
##
|
|
91
|
-
# Parameter exception
|
|
92
|
-
#
|
|
93
|
-
# Happens during runtime if an error happens during parameter
|
|
94
|
-
# evaluation
|
|
95
|
-
class ParameterException < RuntimeError
|
|
96
|
-
# Parameter object
|
|
97
|
-
attr_reader :parameter
|
|
98
|
-
|
|
99
|
-
def message
|
|
100
|
-
cause.nil? ? super : "#{super} : #{cause.message}"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def initialize(target_parameter, custom_message)
|
|
104
|
-
@parameter = target_parameter
|
|
105
|
-
super(custom_message)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
##
|
|
110
|
-
# If something happens during parameter calculation
|
|
111
|
-
class NestedParameterException < ParameterException
|
|
112
|
-
def initialize(target_parameter)
|
|
113
|
-
super(
|
|
114
|
-
target_parameter,
|
|
115
|
-
'Exception was thrown by nested parameter while calculating ' \
|
|
116
|
-
"#{target_parameter.name} (#{target_parameter.description})"
|
|
117
|
-
)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
##
|
|
122
|
-
# A value failed constraints
|
|
123
|
-
class ParameterValueInvalid < ParameterException
|
|
124
|
-
attr_reader :value
|
|
125
|
-
attr_reader :object
|
|
126
|
-
|
|
127
|
-
def initialize(target_parameter, target_object, target_value)
|
|
128
|
-
@value = target_value
|
|
129
|
-
@object = target_object
|
|
130
|
-
super(
|
|
131
|
-
target_parameter,
|
|
132
|
-
message_text(target_parameter, target_object, target_value)
|
|
133
|
-
)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
private
|
|
137
|
-
|
|
138
|
-
def message_text(target_parameter, target_object, target_value)
|
|
139
|
-
message = "Value '(#{target_value.inspect})' violates constraints specified for " \
|
|
140
|
-
"#{target_parameter.name} (#{target_parameter.description}) in " \
|
|
141
|
-
"#{target_parameter.klass}"
|
|
142
|
-
|
|
143
|
-
unless target_object.class == target_parameter.klass
|
|
144
|
-
message += " and inherited by #{target_object.class}"
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
message
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
##
|
|
152
|
-
# Getter is not specified
|
|
153
|
-
#
|
|
154
|
-
# Getter wasn't specified neither for the individual parameter nor for the mixing instance nor
|
|
155
|
-
# for its class.
|
|
156
|
-
class ParameterGetterIsNotDefined < ParameterException
|
|
157
|
-
def initialize(target_parameter)
|
|
158
|
-
super(
|
|
159
|
-
target_parameter,
|
|
160
|
-
"Can't find getter for #{target_parameter.name} (#{target_parameter.description}): " \
|
|
161
|
-
'a getter should be attached either to the parameter or the instance ' \
|
|
162
|
-
'or the instance class'
|
|
163
|
-
)
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
##
|
|
168
|
-
# Options exception
|
|
169
|
-
#
|
|
170
|
-
# The parent of all exceptions Options method can throw
|
|
171
|
-
class OptionError < ArgumentError
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
##
|
|
175
|
-
# Recursive value is expected
|
|
176
|
-
#
|
|
177
|
-
# Value passed doesn't not support "recursive" contract. See Utils.recursive?
|
|
178
|
-
class OptionShouldBeRecursive < OptionError
|
|
179
|
-
attr_reader :value
|
|
180
|
-
|
|
181
|
-
def initialize(value)
|
|
182
|
-
@value = value
|
|
183
|
-
super("Value #{value} is not a recursive data structure")
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
##
|
|
188
|
-
# Deleted branch detected
|
|
189
|
-
#
|
|
190
|
-
# While traversing Options layers for a value, deleted branch marker was discovered.
|
|
191
|
-
class OptionValueDeleted < OptionError
|
|
192
|
-
attr_reader :path
|
|
193
|
-
|
|
194
|
-
def initialize(path)
|
|
195
|
-
@path = path
|
|
196
|
-
super(
|
|
197
|
-
"Deleted value was detected while traversing path. The path left untraversed: #{path}"
|
|
198
|
-
)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
##
|
|
203
|
-
# Scalar is met while traversing Options path
|
|
204
|
-
#
|
|
205
|
-
# Path is not empty yet but we can't traverse deeper because the current value is a scalar
|
|
206
|
-
class OptionScalarOnTheWay < OptionError
|
|
207
|
-
attr_reader :value
|
|
208
|
-
attr_reader :path
|
|
209
|
-
|
|
210
|
-
def initialize(value, path)
|
|
211
|
-
@value = value
|
|
212
|
-
@path = path
|
|
213
|
-
|
|
214
|
-
super(
|
|
215
|
-
"Value #{value} is not a recursive data structure and we have still #{path} keys " \
|
|
216
|
-
'to look-up'
|
|
217
|
-
)
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/exceptions'
|
|
2
|
-
|
|
3
|
-
module Aws
|
|
4
|
-
module Templates
|
|
5
|
-
module Render
|
|
6
|
-
##
|
|
7
|
-
# View registry
|
|
8
|
-
#
|
|
9
|
-
# View registries encapsulate differerent ways of transforming
|
|
10
|
-
# your artifacts into a domain-specific output.
|
|
11
|
-
# In nutshell, they are registries of View classes which are able
|
|
12
|
-
# to lookup proper View for object instance passed to it.
|
|
13
|
-
class Registry
|
|
14
|
-
# View registry accessor
|
|
15
|
-
def registry
|
|
16
|
-
@registry ||= {}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# Register pair artifact-view
|
|
21
|
-
#
|
|
22
|
-
# Invoked from inside of a View class at definition of the link
|
|
23
|
-
# between the view class and an artifact
|
|
24
|
-
# * +artifact+ - artifact class the view claims to be able to render
|
|
25
|
-
# * +render+ - view class
|
|
26
|
-
def register(artifact, view)
|
|
27
|
-
registry[artifact] = view
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
# Can object be rendered
|
|
32
|
-
#
|
|
33
|
-
# Returns true if the object passed can be rendered by one of the views in the registry
|
|
34
|
-
def can_render?(instance)
|
|
35
|
-
instance.class.ancestors.any? { |ancestor| registry.include?(ancestor) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
##
|
|
39
|
-
# Lookup a view for the artifact
|
|
40
|
-
#
|
|
41
|
-
# Searches registry for artifact's class and all its ancestors
|
|
42
|
-
# in the registry and returns the closest matching view
|
|
43
|
-
# * +instance+ - artifact instance to render
|
|
44
|
-
# * +params+ - assigned parameters; it can be arbitrary value;
|
|
45
|
-
# it is propagated to selected render
|
|
46
|
-
def view_for(instance, params = nil)
|
|
47
|
-
return instance if instance.respond_to?(:to_rendered)
|
|
48
|
-
|
|
49
|
-
mod = instance.class.ancestors.find do |ancestor|
|
|
50
|
-
registry.include?(ancestor)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
raise ViewNotFound.new(instance) unless mod
|
|
54
|
-
|
|
55
|
-
registry[mod].new(instance, params)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
require 'aws/templates/exceptions'
|
|
2
|
-
require 'aws/templates/utils'
|
|
3
|
-
require 'aws/templates/utils/options'
|
|
4
|
-
require 'aws/templates/utils/inheritable'
|
|
5
|
-
|
|
6
|
-
module Aws
|
|
7
|
-
module Templates
|
|
8
|
-
module Utils
|
|
9
|
-
##
|
|
10
|
-
# Filtered mixin.
|
|
11
|
-
#
|
|
12
|
-
# It implements class instance-based definitions of option filters.
|
|
13
|
-
# Filters are options hash alterations and transformations
|
|
14
|
-
# which are defined per-class basis and applied according to class
|
|
15
|
-
# hierarchy when invoked. The target mixing entity should be either
|
|
16
|
-
# Module or Class. In the former case it's possible to model set of
|
|
17
|
-
# object which have common traits organized as an arbitrary graph
|
|
18
|
-
# with many-to-many relationship.
|
|
19
|
-
#
|
|
20
|
-
# Important difference from defaults is that the transformations
|
|
21
|
-
# are performed on a copy of options returned by a separate "filtered"
|
|
22
|
-
# accessor and not in place.
|
|
23
|
-
module Contextualized
|
|
24
|
-
include Inheritable
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
# Filter functor class
|
|
28
|
-
#
|
|
29
|
-
# A filter is a Proc accepting input hash and providing output
|
|
30
|
-
# hash which is expected to be a permutation of the input.
|
|
31
|
-
# The proc is executed in instance context so instance methods can
|
|
32
|
-
# be used for calculation.
|
|
33
|
-
#
|
|
34
|
-
# The class implements functor pattern through to_proc method and
|
|
35
|
-
# closure. Essentially, all filters can be used everywhere where
|
|
36
|
-
# a block is expected.
|
|
37
|
-
#
|
|
38
|
-
# It provides protected method filter which should be overriden in
|
|
39
|
-
# all concrete filter classes.
|
|
40
|
-
class Filter
|
|
41
|
-
##
|
|
42
|
-
# Proc proxy
|
|
43
|
-
#
|
|
44
|
-
# Just passes opts to the proc the filter was initialized with. It is used internaly.
|
|
45
|
-
class Proxy < Filter
|
|
46
|
-
attr_reader :proc
|
|
47
|
-
|
|
48
|
-
def initialize(prc, &blk)
|
|
49
|
-
@proc = prc || blk
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def filter(opts, memo, instance)
|
|
53
|
-
instance.instance_exec(opts, memo, &proc)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
##
|
|
58
|
-
# No-op filter
|
|
59
|
-
#
|
|
60
|
-
# No-op filter or identity filter doesn't perform any operations on passed options. The
|
|
61
|
-
# role of this filter is to play the role of identity function in par with lambda
|
|
62
|
-
# calculus.
|
|
63
|
-
#
|
|
64
|
-
# === Examples
|
|
65
|
-
#
|
|
66
|
-
# class Piece
|
|
67
|
-
# include Aws::Templates::Utils::Contextualized
|
|
68
|
-
#
|
|
69
|
-
# contextualize filter(:identity)
|
|
70
|
-
# end
|
|
71
|
-
#
|
|
72
|
-
# i = Piece.new
|
|
73
|
-
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
74
|
-
# opts.filter(i.filter) # => {}
|
|
75
|
-
class Identity < Filter
|
|
76
|
-
def self.new
|
|
77
|
-
@singleton ||= super()
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def filter(_, memo, _)
|
|
81
|
-
memo
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def &(other)
|
|
85
|
-
other.to_filter
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
##
|
|
90
|
-
# Statically scoped filter
|
|
91
|
-
#
|
|
92
|
-
# Scoped filter wraps whatever Proc obejct passed to it into specified scope for
|
|
93
|
-
# execution. So whatever the scope the filter is called in, it will always be evaluated
|
|
94
|
-
# in the same scope specified at creation.
|
|
95
|
-
#
|
|
96
|
-
# The filter is used by the internal mechanics of the framework.
|
|
97
|
-
class Scoped < Filter
|
|
98
|
-
attr_reader :scoped_filter
|
|
99
|
-
attr_reader :scope
|
|
100
|
-
|
|
101
|
-
def initialize(fltr, scp)
|
|
102
|
-
@scoped_filter = _check_filter(fltr)
|
|
103
|
-
@scope = scp
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def filter(options, memo, _)
|
|
107
|
-
scope.instance_exec(options, memo, &scoped_filter)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
private
|
|
111
|
-
|
|
112
|
-
def _check_filter(fltr)
|
|
113
|
-
raise "#{fltr} is not a filter" unless fltr.respond_to?(:to_proc)
|
|
114
|
-
fltr
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
##
|
|
119
|
-
# Add all options into the context
|
|
120
|
-
#
|
|
121
|
-
# The filter performs deep copy of entire options hash with consecutive merge into the
|
|
122
|
-
# resulting context
|
|
123
|
-
#
|
|
124
|
-
# === Example
|
|
125
|
-
#
|
|
126
|
-
# class Piece
|
|
127
|
-
# contextualize filter(:copy)
|
|
128
|
-
# end
|
|
129
|
-
#
|
|
130
|
-
# i = Piece.new()
|
|
131
|
-
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
132
|
-
# opts.filter(i.filter) # => { a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 } }
|
|
133
|
-
class Copy < Filter
|
|
134
|
-
PRE_FILTER = %i[label root parent].freeze
|
|
135
|
-
|
|
136
|
-
def filter(opts, memo, _)
|
|
137
|
-
result = Utils.deep_dup(opts.to_hash)
|
|
138
|
-
PRE_FILTER.each { |k| result.delete(k) }
|
|
139
|
-
Utils.merge(memo, result)
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
##
|
|
144
|
-
# Base class for recursive operations
|
|
145
|
-
#
|
|
146
|
-
# Internally used by Add and Remove filters.
|
|
147
|
-
class RecursiveSchemaFilter < Filter
|
|
148
|
-
attr_reader :scheme
|
|
149
|
-
|
|
150
|
-
def initialize(*args)
|
|
151
|
-
schm = if args.last.respond_to?(:to_hash)
|
|
152
|
-
args.each_with_object(args.pop) do |field, hsh|
|
|
153
|
-
hsh[field] = nil
|
|
154
|
-
hsh
|
|
155
|
-
end
|
|
156
|
-
else
|
|
157
|
-
args
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
@scheme = _check_scheme(schm)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
private
|
|
164
|
-
|
|
165
|
-
def _check_scheme(schm)
|
|
166
|
-
if schm.respond_to?(:to_hash)
|
|
167
|
-
schm.to_hash.each_pair { |_, sub| _check_scheme(sub) unless sub.nil? }
|
|
168
|
-
elsif !schm.respond_to?(:to_a)
|
|
169
|
-
raise "#{schm.inspect} is not appropriate branch in the scheme"
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
schm
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
##
|
|
177
|
-
# Add specified keys into the hash
|
|
178
|
-
#
|
|
179
|
-
# Selective version of Copy filter. It adds key-value pairs or whole subtrees from
|
|
180
|
-
# options into the memo hash. It does this according to specified schema represented
|
|
181
|
-
# by combination of nested hashes and arrays. User can specify addition of values
|
|
182
|
-
# at arbitrary depth in options hash hierarchy with arbitrar granularity.
|
|
183
|
-
#
|
|
184
|
-
# === Example
|
|
185
|
-
#
|
|
186
|
-
# class Piece
|
|
187
|
-
# include Aws::Templates::Utils::Contextualized
|
|
188
|
-
#
|
|
189
|
-
# contextualize filter(:add, :a, :b, c: [:d])
|
|
190
|
-
# end
|
|
191
|
-
#
|
|
192
|
-
# i = Piece.new()
|
|
193
|
-
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
194
|
-
# opts.filter(i.filter) # => { a: { q: 1 }, b: 2, c: { d: { r: 5 } } }
|
|
195
|
-
class Add < RecursiveSchemaFilter
|
|
196
|
-
def filter(options, memo, _)
|
|
197
|
-
_recurse_add(options, memo, scheme)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
private
|
|
201
|
-
|
|
202
|
-
def _recurse_add(opts, memo, schm)
|
|
203
|
-
return unless Utils.recursive?(opts)
|
|
204
|
-
|
|
205
|
-
if Utils.hashable?(schm)
|
|
206
|
-
_scheme_add(opts, memo, schm.to_hash)
|
|
207
|
-
elsif Utils.list?(schm)
|
|
208
|
-
_list_add(opts, memo, schm.to_ary)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
memo
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def _list_add(opts, memo, list)
|
|
215
|
-
list.each { |field| memo[field] = Utils.merge(memo[field], opts[field]) }
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
def _scheme_add(opts, memo, schm)
|
|
219
|
-
schm.each_pair do |field, sub_scheme|
|
|
220
|
-
next unless opts.include?(field)
|
|
221
|
-
memo[field] = if sub_scheme.nil?
|
|
222
|
-
Utils.merge(memo[field], opts[field])
|
|
223
|
-
else
|
|
224
|
-
_recurse_add(opts[field], memo[field] || {}, sub_scheme)
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
##
|
|
231
|
-
# Remove specified keys from hash
|
|
232
|
-
#
|
|
233
|
-
# The filter performs removal of values from options hash
|
|
234
|
-
# according to specified schema represented by combination of
|
|
235
|
-
# nested hashes and arrays. User can specify removal of values
|
|
236
|
-
# at arbitrary depth in options hash hierarchy with arbitrary
|
|
237
|
-
# granularity.
|
|
238
|
-
#
|
|
239
|
-
# === Example
|
|
240
|
-
#
|
|
241
|
-
# class Piece
|
|
242
|
-
# include Aws::Templates::Utils::Contextualized
|
|
243
|
-
#
|
|
244
|
-
# contextualize filter(:copy) & filter(:remove, :a, :b, c: [:d])
|
|
245
|
-
# end
|
|
246
|
-
#
|
|
247
|
-
# i = Piece.new()
|
|
248
|
-
# opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
|
|
249
|
-
# opts.filter(i.filter) # => { c: { e: 1 } }
|
|
250
|
-
class Remove < RecursiveSchemaFilter
|
|
251
|
-
def filter(_, memo, _)
|
|
252
|
-
_recurse_remove(memo, scheme)
|
|
253
|
-
memo
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
private
|
|
257
|
-
|
|
258
|
-
def _recurse_remove(opts, schm)
|
|
259
|
-
return unless Utils.recursive?(opts)
|
|
260
|
-
|
|
261
|
-
if Utils.hashable?(schm)
|
|
262
|
-
_scheme_remove(opts, schm.to_hash)
|
|
263
|
-
elsif Utils.list?(schm)
|
|
264
|
-
_list_remove(opts, schm.to_ary)
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def _list_remove(opts, list)
|
|
269
|
-
list.each { |field| opts.delete(field) }
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
def _scheme_remove(opts, schm)
|
|
273
|
-
schm.each_pair do |field, sub_scheme|
|
|
274
|
-
if sub_scheme.nil?
|
|
275
|
-
opts.delete(field)
|
|
276
|
-
elsif opts.include?(field)
|
|
277
|
-
_recurse_remove(opts[field], sub_scheme)
|
|
278
|
-
end
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
##
|
|
284
|
-
# Override specified keys in options hash
|
|
285
|
-
#
|
|
286
|
-
# The filter performs merge the hash passed at initialization with
|
|
287
|
-
# options hash. Either hash itself or block returning a hash
|
|
288
|
-
# can be specified. The block will be evaluated in instance context
|
|
289
|
-
# so all instance methods are accessible.
|
|
290
|
-
#
|
|
291
|
-
# === Example
|
|
292
|
-
#
|
|
293
|
-
# class Piece
|
|
294
|
-
# include Aws::Templates::Utils::Contextualized
|
|
295
|
-
#
|
|
296
|
-
# contextualize filter(:copy) & filter(:override, a: 12, b: 15, c: { d: 30 })
|
|
297
|
-
# end
|
|
298
|
-
#
|
|
299
|
-
# i = Piece.new
|
|
300
|
-
# opts = Options.new(c: { e: 1 })
|
|
301
|
-
# opts.filter(i.filter) # => { a: 12, b: 15, c: { d: 30, e: 1 } }
|
|
302
|
-
class Override < Filter
|
|
303
|
-
attr_reader :override
|
|
304
|
-
|
|
305
|
-
def initialize(override = nil, &override_block)
|
|
306
|
-
@override = _check_override_type(override || override_block)
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
def filter(_, memo, instance)
|
|
310
|
-
Utils.merge(
|
|
311
|
-
memo,
|
|
312
|
-
if override.respond_to?(:to_hash)
|
|
313
|
-
override
|
|
314
|
-
elsif override.respond_to?(:to_proc)
|
|
315
|
-
instance.instance_eval(&override)
|
|
316
|
-
end
|
|
317
|
-
)
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
private
|
|
321
|
-
|
|
322
|
-
def _check_override_type(ovrr)
|
|
323
|
-
raise "Wrong override value: #{ovrr.inspect}" unless _proper_override_type?(ovrr)
|
|
324
|
-
ovrr
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
def _proper_override_type?(ovrr)
|
|
328
|
-
ovrr.respond_to?(:to_hash) || ovrr.respond_to?(:to_proc)
|
|
329
|
-
end
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
##
|
|
333
|
-
# Chain filters
|
|
334
|
-
#
|
|
335
|
-
# The filter chains all passed filters to have chained
|
|
336
|
-
# filter semantics.
|
|
337
|
-
#
|
|
338
|
-
# === Example
|
|
339
|
-
#
|
|
340
|
-
# class Piece
|
|
341
|
-
# include Aws::Templates::Utils::Contextualized
|
|
342
|
-
#
|
|
343
|
-
# contextualize filter(:copy) & filter(:remove, :c) & filter(:override, a: 12, b: 15)
|
|
344
|
-
# end
|
|
345
|
-
#
|
|
346
|
-
# i = Piece.new
|
|
347
|
-
# opts = Options.new(c: { e: 1 })
|
|
348
|
-
# opts.filter(i.filter) # => { a: 12, b: 15 }
|
|
349
|
-
class Chain < Filter
|
|
350
|
-
attr_reader :filters
|
|
351
|
-
|
|
352
|
-
def initialize(*flts)
|
|
353
|
-
wrong_objects = flts.reject { |f| f.respond_to?(:to_proc) }
|
|
354
|
-
unless wrong_objects.empty?
|
|
355
|
-
raise(
|
|
356
|
-
"The following objects are not filters: #{wrong_objects.inspect}"
|
|
357
|
-
)
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
@filters = flts
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
def filter(options, memo, instance)
|
|
364
|
-
filters.inject(memo) { |acc, elem| instance.instance_exec(options, acc, &elem) }
|
|
365
|
-
end
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
##
|
|
369
|
-
# Chain filters
|
|
370
|
-
def &(other)
|
|
371
|
-
fltr = other.to_filter
|
|
372
|
-
return self if fltr.is_a?(Identity)
|
|
373
|
-
Chain.new(self, fltr)
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
##
|
|
377
|
-
# Creates closure with filter invocation
|
|
378
|
-
#
|
|
379
|
-
# It's an interface method required for Filter to expose
|
|
380
|
-
# functor properties. It encloses invocation of Filter
|
|
381
|
-
# filter method into a closure. The closure itself is
|
|
382
|
-
# executed in the context of Filtered instance which provides
|
|
383
|
-
# proper set "self" variable.
|
|
384
|
-
#
|
|
385
|
-
# The closure itself accepts just one parameter:
|
|
386
|
-
# * +opts+ - input hash to be filtered
|
|
387
|
-
# ...where instance is assumed from self
|
|
388
|
-
def to_proc
|
|
389
|
-
fltr = self
|
|
390
|
-
->(opts, memo = {}) { fltr.filter(opts, memo, self) }
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
##
|
|
394
|
-
# Filter method
|
|
395
|
-
#
|
|
396
|
-
# * +opts+ - input hash to be filtered
|
|
397
|
-
# * +instance+ - the instance filter is executed in
|
|
398
|
-
def filter(opts, memo, instance); end
|
|
399
|
-
|
|
400
|
-
def to_filter
|
|
401
|
-
self
|
|
402
|
-
end
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
##
|
|
406
|
-
# Mixin for filter factory method
|
|
407
|
-
#
|
|
408
|
-
# Adds filter factory method to the target
|
|
409
|
-
module FilterFactory
|
|
410
|
-
##
|
|
411
|
-
# Filter factory method
|
|
412
|
-
#
|
|
413
|
-
# It creates a filter based on type identifier and parameters with optional block which
|
|
414
|
-
# will be passed unchanged to the filter constructor
|
|
415
|
-
# * +type+ - type identifier; can by either symbol or string
|
|
416
|
-
# * +args+ - filter constructor arguments
|
|
417
|
-
# * +blk+ - optional block to be passed to filter constructor
|
|
418
|
-
def filter(type, *args, &blk)
|
|
419
|
-
Filter.const_get(type.to_s.capitalize).new(*args, &blk)
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
##
|
|
424
|
-
# Class-level mixins
|
|
425
|
-
#
|
|
426
|
-
# It's a DSL extension to declaratively define context filters
|
|
427
|
-
class_scope do
|
|
428
|
-
include FilterFactory
|
|
429
|
-
end
|
|
430
|
-
|
|
431
|
-
instance_scope do
|
|
432
|
-
include FilterFactory
|
|
433
|
-
end
|
|
434
|
-
end
|
|
435
|
-
end
|
|
436
|
-
end
|
|
437
|
-
end
|