Module: Hash::Compositing::HashInterface
- Included in:
- Hash::Compositing
- Defined in:
- lib/hash/compositing/hash_interface.rb
Instance Attribute Summary collapse
-
#parent_composite_object ⇒ Object
(also: #parent_composite_hash)
parent_composite_object # parent_composite_hash #.
Class Method Summary collapse
-
.append_features(instance) ⇒ Object
self.append_features #.
-
.included(instance) ⇒ Object
self.included #.
Instance Method Summary collapse
-
#==(object) ⇒ Object
#.
-
#[](key) ⇒ Object
-
#.
-
#[]=(key, object) ⇒ Object
[]= #.
-
#child_post_delete_hook(key, object) ⇒ Object
child_post_delete_hook #.
-
#child_post_set_hook(key, object) ⇒ Object
child_post_set_hook #.
-
#child_pre_delete_hook(key) ⇒ Object
child_pre_delete_hook #.
-
#child_pre_set_hook(key, object) ⇒ Object
child_pre_set_hook #.
-
#delete(key) ⇒ Object
delete #.
-
#each(*args, &block) ⇒ Object
each #.
-
#freeze! ⇒ Object
freezes configuration and prevents ancestors from changing this configuration in the future.
-
#initialize(parent_composite_hash = nil, configuration_instance = nil) ⇒ Object
initialize #.
-
#initialize_for_parent(parent_composite_hash) ⇒ Object
initialize_for_parent #.
-
#inspect ⇒ Object
inspect #.
-
#register_sub_composite_hash(sub_composite_hash) ⇒ Object
register_sub_composite_hash #.
-
#to_s ⇒ Object
to_s #.
-
#unregister_sub_composite_hash(sub_composite_hash) ⇒ Object
unregister_sub_composite_hash #.
Instance Attribute Details
#parent_composite_object ⇒ Object Also known as: parent_composite_hash
parent_composite_object #
parent_composite_hash #
63 64 65 |
# File 'lib/hash/compositing/hash_interface.rb', line 63 def parent_composite_object @parent_composite_object end |
Class Method Details
.append_features(instance) ⇒ Object
self.append_features #
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hash/compositing/hash_interface.rb', line 8 def self.append_features( instance ) instance.module_eval do private alias_method :non_cascading_store, :[]= alias_method :non_cascading_delete, :delete end super end |
.included(instance) ⇒ Object
self.included #
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hash/compositing/hash_interface.rb', line 28 def self.included( instance ) instance.module_eval do alias_method :store, :[]= end super end |
Instance Method Details
#==(object) ⇒ Object
#
162 163 164 165 166 167 168 |
# File 'lib/hash/compositing/hash_interface.rb', line 162 def ==( object ) load_parent_state super end |
#[](key) ⇒ Object
-
#
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/hash/compositing/hash_interface.rb', line 210 def []( key ) return_value = nil if @parent_key_lookup[ key ] return_value = lazy_set_parent_element_in_self( key ) else return_value = super end return return_value end |
#[]=(key, object) ⇒ Object
[]= #
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/hash/compositing/hash_interface.rb', line 228 def []=( key, object ) @replaced_parents[ key ] = true @parent_key_lookup.delete( key ) super @sub_composite_hashes.each do |this_sub_hash| this_sub_hash.instance_eval do update_as_sub_hash_for_parent_store( key ) end end return object end |
#child_post_delete_hook(key, object) ⇒ Object
child_post_delete_hook #
150 151 152 153 154 |
# File 'lib/hash/compositing/hash_interface.rb', line 150 def child_post_delete_hook( key, object ) return object end |
#child_post_set_hook(key, object) ⇒ Object
child_post_set_hook #
129 130 131 132 133 |
# File 'lib/hash/compositing/hash_interface.rb', line 129 def child_post_set_hook( key, object ) return object end |
#child_pre_delete_hook(key) ⇒ Object
child_pre_delete_hook #
139 140 141 142 143 144 |
# File 'lib/hash/compositing/hash_interface.rb', line 139 def child_pre_delete_hook( key ) # false means delete does not take place return true end |
#child_pre_set_hook(key, object) ⇒ Object
child_pre_set_hook #
119 120 121 122 123 |
# File 'lib/hash/compositing/hash_interface.rb', line 119 def child_pre_set_hook( key, object ) return object end |
#delete(key) ⇒ Object
delete #
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/hash/compositing/hash_interface.rb', line 250 def delete( key ) @replaced_parents.delete( key ) @parent_key_lookup.delete( key ) object = super @sub_composite_hashes.each do |this_sub_hash| this_sub_hash.instance_eval do update_as_sub_hash_for_parent_delete( key, object ) end end return object end |
#each(*args, &block) ⇒ Object
each #
174 175 176 177 178 179 180 |
# File 'lib/hash/compositing/hash_interface.rb', line 174 def each( *args, & block ) load_parent_state super end |
#freeze! ⇒ Object
freezes configuration and prevents ancestors from changing this configuration in the future
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/hash/compositing/hash_interface.rb', line 273 def freeze! # unregister with parent composite so we don't get future updates from it if @parent_composite_object @parent_composite_object.unregister_sub_composite_hash( self ) end return self end |
#initialize(parent_composite_hash = nil, configuration_instance = nil) ⇒ Object
initialize #
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hash/compositing/hash_interface.rb', line 44 def initialize( parent_composite_hash = nil, configuration_instance = nil ) super( configuration_instance ) @replaced_parents = { } @parent_key_lookup = { } # we may later have our own child composites that register with us @sub_composite_hashes = [ ] initialize_for_parent( parent_composite_hash ) end |
#initialize_for_parent(parent_composite_hash) ⇒ Object
initialize_for_parent #
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hash/compositing/hash_interface.rb', line 73 def initialize_for_parent( parent_composite_hash ) if @parent_composite_object = parent_composite_hash @parent_composite_object.register_sub_composite_hash( self ) # @parent_key_lookup tracks keys that we have not yet received from parent @parent_composite_object.each do |this_key, this_object| @parent_key_lookup[ this_key ] = true non_cascading_store( this_key, nil ) end end end |
#inspect ⇒ Object
inspect #
198 199 200 201 202 203 204 |
# File 'lib/hash/compositing/hash_interface.rb', line 198 def inspect load_parent_state super end |
#register_sub_composite_hash(sub_composite_hash) ⇒ Object
register_sub_composite_hash #
93 94 95 96 97 98 99 |
# File 'lib/hash/compositing/hash_interface.rb', line 93 def register_sub_composite_hash( sub_composite_hash ) @sub_composite_hashes.push( sub_composite_hash ) return self end |
#to_s ⇒ Object
to_s #
186 187 188 189 190 191 192 |
# File 'lib/hash/compositing/hash_interface.rb', line 186 def to_s load_parent_state super end |
#unregister_sub_composite_hash(sub_composite_hash) ⇒ Object
unregister_sub_composite_hash #
105 106 107 108 109 110 111 |
# File 'lib/hash/compositing/hash_interface.rb', line 105 def unregister_sub_composite_hash( sub_composite_hash ) @sub_composite_hashes.delete( sub_composite_hash ) return self end |