cascading-configuration-hash 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 3
9
- version: 1.1.3
8
+ - 4
9
+ version: 1.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Asher
@@ -39,20 +39,9 @@ extensions: []
39
39
  extra_rdoc_files: []
40
40
 
41
41
  files:
42
- - lib/cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb
43
- - lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb
44
- - lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb
45
- - lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb
46
- - lib/cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb
47
- - lib/cascading-configuration-hash/CascadingConfiguration/Hash/ClassInstance.rb
48
- - lib/cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInstance.rb
49
- - lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb
50
- - lib/cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb
51
- - lib/cascading-configuration-hash.rb
52
- - spec/CascadingConfiguration/CascadingCompositeHash_spec.rb
53
- - spec/CascadingConfiguration/ConfigurationHash_spec.rb
54
- - spec/CascadingConfiguration/Hash/Accessors_spec.rb
55
- - spec/CascadingConfiguration/Hash_spec.rb
42
+ - lib/cascading-configuration/CascadingConfiguration.rb
43
+ - lib/cascading-configuration.rb
44
+ - spec/CascadingConfiguration_spec.rb
56
45
  - README.md
57
46
  - README.rdoc
58
47
  has_rdoc: true
@@ -1,39 +0,0 @@
1
-
2
- module CascadingConfiguration::CompositingHash::Instance
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ###################
7
- # self.included #
8
- ###################
9
-
10
- def self.included( class_or_module )
11
- module_self = self
12
- class_or_module.instance_eval do
13
- extend module_self
14
- end
15
- end
16
-
17
- ################################################
18
- # composite_hash_for_cascading_configuration #
19
- ################################################
20
-
21
- def composite_hash_for_cascading_configuration( cascading_name )
22
-
23
- composite_hash = nil
24
-
25
- klass = ( is_a?( Module ) ? self : self.class )
26
- accessor_support_module = klass::AccessorSupportModule
27
- self_instance = self
28
- accessor_support_module.instance_eval do
29
- unless composite_hash = ( ( @composite_hashes ||= Hash.new )[ cascading_name ] ||= Hash.new )[ self_instance ]
30
- composite_hash = ::CascadingConfiguration::CompositingHash.new( cascading_name, self_instance )
31
- @composite_hashes[ cascading_name ][ self_instance ] = composite_hash
32
- end
33
- end
34
-
35
- return composite_hash
36
-
37
- end
38
-
39
- end
@@ -1,136 +0,0 @@
1
-
2
- class CascadingConfiguration::CompositingHash < Hash
3
-
4
- attr_accessor :working_instance, :local_cascading_hash
5
-
6
- ################
7
- # initialize #
8
- ################
9
-
10
- def initialize( cascading_name, working_instance )
11
- @cascading_name = cascading_name
12
- @working_class = ( working_instance.is_a?( Module ) ? working_instance : working_instance.class )
13
- @cascading_variable = @working_class::AccessorSupportModule.cascading_variable_name( @cascading_name )
14
- @working_instance = working_instance
15
- # if first ancestor can have a composite array, register self with it in case it gets updated in the future
16
- if ( first_ancestor = @working_instance.first_ancestor ).respond_to?( :composite_hash_for_cascading_configuration )
17
- @parent_composite_hash = first_ancestor.composite_hash_for_cascading_configuration( @cascading_name )
18
- @parent_composite_hash.register_child_composite_hash( self )
19
- end
20
- # get local cascading array (not included in parent composite)
21
- @local_cascading_hash = ::CascadingConfiguration::LocalConfigurationHash.new
22
- # we may later have our own child composites
23
- @child_composite_hashes = ::Array.new
24
- # initialize self status for parent and local
25
- update_self_as_cascading_composite
26
- end
27
-
28
- ###################################
29
- # register_child_composite_hash #
30
- ###################################
31
-
32
- def register_child_composite_hash( child_composite_hash )
33
- @child_composite_hashes.push( child_composite_hash )
34
- return self
35
- end
36
-
37
- #####################################
38
- # unregister_child_composite_hash #
39
- #####################################
40
-
41
- def unregister_child_composite_hash( child_composite_hash )
42
- @child_composite_hashes.delete( child_composite_hash )
43
- return self
44
- end
45
-
46
- #########
47
- # []= #
48
- #########
49
-
50
- def []=( key, value )
51
- @local_cascading_hash[ key ] = value
52
- update_adding_composite_elements( key => value )
53
- end
54
- alias_method :store, :[]=
55
-
56
- ############
57
- # delete #
58
- ############
59
-
60
- alias_method :super_delete, :delete
61
- def delete( key )
62
- value = self[ key ]
63
- @local_cascading_hash.delete( key )
64
- update_removing_composite_elements( key )
65
- return value
66
- end
67
-
68
- ############
69
- # merge! #
70
- ############
71
-
72
- alias_method :super_merge!, :merge!
73
- def merge!( other_hash )
74
- @local_cascading_hash.merge!( other_hash )
75
- update_adding_composite_elements( other_hash )
76
- return self
77
- end
78
-
79
- #############
80
- # replace #
81
- #############
82
-
83
- alias_method :super_replace, :replace
84
- def replace( other_hash )
85
- # clear current values
86
- clear
87
- # merge replacement settings
88
- merge!( other_hash )
89
- update_self_as_cascading_composite
90
- return self
91
- end
92
-
93
- ###########
94
- # shift #
95
- ###########
96
-
97
- def shift
98
- element = super
99
- key = element[ 0 ]
100
- @local_cascading_hash.delete( key )
101
- update_removing_composite_elements( key )
102
- return element
103
- end
104
-
105
- ###########
106
- # clear #
107
- ###########
108
-
109
- alias_method :super_clear, :clear
110
- def clear
111
- # add all existing values to exclude array
112
- keys.each do |this_key|
113
- delete( this_key )
114
- end
115
- update_removing_composite_elements( *self.keys )
116
- return self
117
- end
118
-
119
- #############
120
- # freeze! #
121
- #############
122
-
123
- # freezes configuration and prevents ancestors from changing this configuration in the future
124
- def freeze!
125
-
126
- # move current configuration into local configuration
127
- @local_cascading_hash.replace( self )
128
-
129
- # unregister with parent composite so we don't get future updates from it
130
- @parent_composite_hash.unregister_child_composite_hash( self ) if @parent_composite_hash
131
-
132
- return self
133
-
134
- end
135
-
136
- end
@@ -1,33 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash::Accessors
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ######################################
7
- # define_configuration_hash_setter #
8
- ######################################
9
-
10
- def define_configuration_hash_setter( configuration_name )
11
- configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
12
- self::AccessorSupportModule.module_eval do
13
- define_method( configuration_setter_name ) do |hash|
14
- # we want the hash to supplant existing config
15
- return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
16
- end
17
- end
18
- end
19
-
20
- ######################################
21
- # define_configuration_hash_getter #
22
- ######################################
23
-
24
- def define_configuration_hash_getter( configuration_name )
25
- configuration_getter_name = configuration_name
26
- self::AccessorSupportModule.module_eval do
27
- define_method( configuration_getter_name ) do
28
- return composite_hash_for_cascading_configuration( configuration_name )
29
- end
30
- end
31
- end
32
-
33
- end
@@ -1,24 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash::ClassInstance
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- #############################
7
- # attr_configuration_hash #
8
- #############################
9
-
10
- def attr_configuration_hash( *property_names, & compositing_block )
11
-
12
- property_names.each do |this_property_name|
13
- self::AccessorSupportModule.set_compositing_proc( this_property_name, compositing_block ) if block_given?
14
- # define configuration setter
15
- define_configuration_hash_setter( this_property_name )
16
- # define configuration getter
17
- define_configuration_hash_getter( this_property_name )
18
- end
19
-
20
- return self
21
-
22
- end
23
-
24
- end
@@ -1,36 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash::ModuleInstance
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- ##############
7
- # included #
8
- ##############
9
-
10
- def included( class_or_module )
11
- super if method_defined?( :super )
12
- # CascadingConfiguration::Hash
13
- module_self = self
14
- class_or_module.instance_eval do
15
- # whichever module included CascadingConfiguration::Hash
16
- extend module_self
17
- # cascade CascadingConfiguration::Hash
18
- include CascadingConfiguration::Hash
19
- end
20
- end
21
-
22
- ##############
23
- # extended #
24
- ##############
25
-
26
- def extended( class_or_module )
27
- super if method_defined?( :super )
28
- # CascadingConfiguration::Hash
29
- module_self = self
30
- class_or_module.instance_eval do
31
- # cascade CascadingConfiguration::Hash
32
- include CascadingConfiguration::Hash
33
- end
34
- end
35
-
36
- end
@@ -1,24 +0,0 @@
1
-
2
- module CascadingConfiguration::Hash
3
-
4
- extend CascadingConfiguration::InternalModuleStub
5
-
6
- include CascadingConfiguration::Variable
7
- include CascadingConfiguration::CompositingHash::Instance
8
-
9
- ###################
10
- # self.included #
11
- ###################
12
-
13
- def self.included( class_or_module )
14
- module_self = self
15
- class_or_module.instance_eval do
16
- extend module_self
17
- extend module_self::Accessors
18
- extend module_self::ClassInstance
19
- # module support
20
- extend CascadingConfiguration::Hash::ModuleInstance unless is_a?( Class )
21
- end
22
- end
23
-
24
- end
@@ -1,83 +0,0 @@
1
-
2
- class CascadingConfiguration::LocalConfigurationHash < Hash
3
-
4
- attr_accessor :exclude_array
5
-
6
- ################
7
- # initialize #
8
- ################
9
-
10
- def initialize()
11
- @exclude_array = ::Array.new
12
- end
13
-
14
- #########
15
- # []= #
16
- #########
17
-
18
- def []=( key, value )
19
- super
20
- remove_from_exclude_array( key )
21
- end
22
-
23
- ###########
24
- # store #
25
- ###########
26
-
27
- def store( key, value )
28
- self[ key ] = value
29
- end
30
-
31
- ############
32
- # delete #
33
- ############
34
-
35
- def delete( key )
36
- value = super
37
- add_to_exclude_array( key )
38
- return value
39
- end
40
-
41
- ############
42
- # merge! #
43
- ############
44
-
45
- def merge!( other_hash )
46
- super
47
- remove_from_exclude_array( *other_hash.keys )
48
- return self
49
- end
50
-
51
- #############
52
- # replace #
53
- #############
54
-
55
- def replace( other_hash )
56
- add_to_exclude_array( *self.keys )
57
- super
58
- end
59
-
60
- ###########
61
- # shift #
62
- ###########
63
-
64
- def shift
65
- element = super
66
- add_to_exclude_array( element )
67
- return element
68
- end
69
-
70
- ###########
71
- # clear #
72
- ###########
73
-
74
- def clear
75
- # add all existing values to exclude array
76
- self.each do |this_key, this_value|
77
- delete( this_key )
78
- end
79
- # clear existing values
80
- super
81
- end
82
-
83
- 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::AccessorSupportModule.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
@@ -1,35 +0,0 @@
1
-
2
- if $cascading_configuration_development
3
- require_relative '../../variable/lib/cascading-configuration-variable.rb'
4
- else
5
- require 'cascading-configuration-variable'
6
- end
7
-
8
- module CascadingConfiguration
9
- class CompositingHash < Hash
10
- module Instance
11
- end
12
- end
13
- class LocalConfigurationHash < Hash
14
- end
15
- module Hash
16
- module Accessors
17
- end
18
- module ClassInstance
19
- end
20
- module ObjectInstance
21
- end
22
- module ModuleInstance
23
- end
24
- end
25
- end
26
-
27
- require_relative 'cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb'
28
- require_relative 'cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb'
29
- require_relative 'cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb'
30
- require_relative 'cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb'
31
- require_relative 'cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb'
32
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash.rb'
33
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb'
34
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/ClassInstance.rb'
35
- require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInstance.rb'