cascading-configuration-hash 1.4.1 → 1.5.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.
Files changed (19) hide show
  1. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb +86 -27
  2. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +5 -21
  3. data/lib/cascading-configuration-hash/{CascadingConfiguration → _private_/CascadingConfiguration/Hash/CompositingHash}/LocalConfigurationHash.rb +29 -2
  4. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/CompositingHash.rb +246 -0
  5. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/Interface/GettersSetters.rb +233 -0
  6. data/lib/cascading-configuration-hash/_private_/CascadingConfiguration/Hash/ModuleSupportMethods.rb +29 -0
  7. data/lib/cascading-configuration-hash.rb +12 -23
  8. data/spec/CascadingConfiguration/Hash_spec.rb +2 -3
  9. data/spec/{CascadingConfiguration → _private_/CascadingConfiguration/Hash/CompositingHash}/LocalConfigurationHash_spec.rb +9 -9
  10. data/spec/_private_/CascadingConfiguration/Hash/CompositingHash_spec.rb +347 -0
  11. metadata +10 -28
  12. data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb +0 -31
  13. data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb +0 -135
  14. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/AccessorDefinitionMethods.rb +0 -149
  15. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface/Instance.rb +0 -26
  16. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb +0 -79
  17. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb +0 -31
  18. data/spec/CascadingConfiguration/CascadingCompositeHash_spec.rb +0 -416
  19. data/spec/CascadingConfiguration/Hash/AccessorDefinitionMethods_spec.rb +0 -30
@@ -1,149 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash::AccessorDefinitionMethods
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ##################################
7
- # define_cascading_hash_setter #
8
- ##################################
9
-
10
- def define_cascading_hash_setter( configuration_name )
11
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
12
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
13
- accessor_module_support.module_eval do
14
- define_method( configuration_setter_name ) do |hash|
15
- # we want the hash to supplant existing config
16
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
17
- end
18
- end
19
- end
20
- end
21
-
22
- ##################################
23
- # define_cascading_hash_getter #
24
- ##################################
25
-
26
- def define_cascading_hash_getter( configuration_name )
27
- configuration_getter_name = configuration_name
28
- [ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
29
- accessor_module_support.module_eval do
30
- define_method( configuration_getter_name ) do
31
- return composite_hash_for_cascading_configuration( configuration_name )
32
- end
33
- end
34
- end
35
- end
36
-
37
- ############################################
38
- # define_class_configuration_hash_setter #
39
- ############################################
40
-
41
- def define_class_configuration_hash_setter( configuration_name )
42
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
43
- accessor_module_support.module_eval do
44
- define_method( configuration_setter_name ) do |hash|
45
- # we want the hash to supplant existing config
46
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
47
- end
48
- end
49
- end
50
-
51
- ############################################
52
- # define_class_configuration_hash_getter #
53
- ############################################
54
-
55
- def define_class_configuration_hash_getter( configuration_name )
56
- configuration_getter_name = configuration_name
57
- accessor_module_support.module_eval do
58
- define_method( configuration_getter_name ) do
59
- return composite_hash_for_cascading_configuration( configuration_name )
60
- end
61
- end
62
- end
63
-
64
- ############################################
65
- # define_local_configuration_hash_setter #
66
- ############################################
67
-
68
- def define_local_configuration_hash_setter( configuration_name )
69
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
70
- [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
71
- module_support.module_eval do
72
- define_method( configuration_setter_name ) do |hash|
73
- # we want the hash to supplant existing config
74
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
75
- end
76
- end
77
- end
78
- end
79
-
80
- ############################################
81
- # define_local_configuration_hash_getter #
82
- ############################################
83
-
84
- def define_local_configuration_hash_getter( configuration_name )
85
- configuration_getter_name = configuration_name
86
- [ accessor_instance_support, accessor_local_instance_support ].compact.each do |module_support|
87
- module_support.module_eval do
88
- define_method( configuration_getter_name ) do
89
- return composite_hash_for_cascading_configuration( configuration_name )
90
- end
91
- end
92
- end
93
- end
94
-
95
- ###############################################
96
- # define_instance_configuration_hash_setter #
97
- ###############################################
98
-
99
- def define_instance_configuration_hash_setter( configuration_name )
100
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
101
- accessor_instance_support.module_eval do
102
- define_method( configuration_setter_name ) do |hash|
103
- # we want the hash to supplant existing config
104
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
105
- end
106
- end
107
- end
108
-
109
- ###############################################
110
- # define_instance_configuration_hash_getter #
111
- ###############################################
112
-
113
- def define_instance_configuration_hash_getter( configuration_name )
114
- configuration_getter_name = configuration_name
115
- accessor_instance_support.module_eval do
116
- define_method( configuration_getter_name ) do
117
- return composite_hash_for_cascading_configuration( configuration_name )
118
- end
119
- end
120
- end
121
-
122
- #############################################
123
- # define_object_configuration_hash_setter #
124
- #############################################
125
-
126
- def define_object_configuration_hash_setter( configuration_name )
127
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
128
- accessor_local_instance_support.module_eval do
129
- define_method( configuration_setter_name ) do |hash|
130
- # we want the hash to supplant existing config
131
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
132
- end
133
- end
134
- end
135
-
136
- #############################################
137
- # define_object_configuration_hash_getter #
138
- #############################################
139
-
140
- def define_object_configuration_hash_getter( configuration_name )
141
- configuration_getter_name = configuration_name
142
- accessor_local_instance_support.module_eval do
143
- define_method( configuration_getter_name ) do
144
- return composite_hash_for_cascading_configuration( configuration_name )
145
- end
146
- end
147
- end
148
-
149
- end
@@ -1,26 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash::Interface::Instance
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ######################################
7
- # attr_instance_configuration_hash #
8
- ######################################
9
-
10
- # defines configuration in present class or module context
11
- # configuration does not cascade
12
- def attr_instance_configuration_hash( *property_names, & compositing_block )
13
-
14
- property_names.each do |this_property_name|
15
- accessor_module_support.set_compositing_proc( this_property_name, compositing_block ) if block_given?
16
- # define configuration setter
17
- define_instance_configuration_hash_setter( this_property_name )
18
- # define configuration getter
19
- define_instance_configuration_hash_getter( this_property_name )
20
- end
21
-
22
- return self
23
-
24
- end
25
-
26
- end
@@ -1,79 +0,0 @@
1
-
2
- class CascadingConfiguration::CompositingHash < Hash
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- ########################################
9
- # update_self_as_cascading_composite #
10
- ########################################
11
-
12
- def update_self_as_cascading_composite
13
- # start fresh
14
- super_clear
15
- update_composite_self_for_parent_hash( @parent_composite_hash, @local_cascading_hash )
16
- # remove local exclude
17
- unless @local_cascading_hash.exclude_array.empty?
18
- @local_cascading_hash.exclude_array.each do |this_excluded_element|
19
- super_delete( this_excluded_element )
20
- end
21
- end
22
- # notify children to update their composite status
23
- update_child_composite_arrays
24
- return self
25
- end
26
-
27
- ######################################
28
- # update_adding_composite_elements #
29
- ######################################
30
-
31
- def update_adding_composite_elements( elements_to_cascade )
32
- update_composite_self_for_parent_hash( self, elements_to_cascade )
33
- update_child_composite_arrays
34
- return self
35
- end
36
-
37
- ###########################################
38
- # update_composite_self_for_parent_hash #
39
- ###########################################
40
-
41
- def update_composite_self_for_parent_hash( parent_hash, second_hash )
42
- if compositing_proc = @working_class.accessor_module_support.get_compositing_proc( @cascading_name )
43
- # if we have a compositing proc defined, use its result to replace
44
- parent_hash_copy = Hash.new
45
- parent_hash_copy.merge!( parent_hash ) if parent_hash
46
- second_hash_copy = Hash.new
47
- second_hash_copy.merge!( second_hash ) if second_hash
48
- composite_result = compositing_proc.call( parent_hash_copy, second_hash_copy )
49
- super_replace( composite_result )
50
- else
51
- # otherwise we simply merge
52
- super_merge!( parent_hash ) if parent_hash
53
- super_merge!( second_hash ) if second_hash
54
- end
55
- return self
56
- end
57
-
58
- ########################################
59
- # update_removing_composite_elements #
60
- ########################################
61
-
62
- def update_removing_composite_elements( *elements_to_exclude )
63
- elements_to_exclude.each do |this_key|
64
- super_delete( this_key )
65
- end
66
- update_child_composite_arrays
67
- end
68
-
69
- ###################################
70
- # update_child_composite_arrays #
71
- ###################################
72
-
73
- def update_child_composite_arrays
74
- @child_composite_hashes.each do |this_composite_hash|
75
- this_composite_hash.instance_eval { update_self_as_cascading_composite }
76
- end
77
- end
78
-
79
- end
@@ -1,31 +0,0 @@
1
-
2
- class CascadingConfiguration::LocalConfigurationHash < Hash
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- ##########################
9
- # add_to_exclude_array #
10
- ##########################
11
-
12
- def add_to_exclude_array( *elements )
13
- @exclude_array ||= ::Array.new
14
- @exclude_array += elements
15
- @exclude_array.sort!.uniq!
16
- end
17
-
18
- ###############################
19
- # remove_from_exclude_array #
20
- ###############################
21
-
22
- def remove_from_exclude_array( *elements )
23
- if @exclude_array
24
- @exclude_array -= elements
25
- @exclude_array.sort!.uniq!
26
- else
27
- @exclude_array ||= ::Array.new
28
- end
29
- end
30
-
31
- end