Class: Module::Cluster::InstanceController::HookController::ChainProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb

Overview

An InstanceController uses an InstanceController::HookController::ChainProxy to chain commands

that rely on chained state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_hook_controller) ⇒ ChainProxy

Returns a new instance of ChainProxy.

Parameters:

  • parent_hook_controller

    Hook Controller for which this Chain Proxy is operative.



17
18
19
20
21
22
23
24
25
26
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 17

def initialize( parent_hook_controller )
  
  @parent_hook_controller = parent_hook_controller
  
  @contexts = [ ]
  @cascades_to = [ ]
  
  @index = -1
  
end

Instance Attribute Details

#cascades_toArray<Symbol,nil> (readonly)

Contexts (nil, :module, :class, :subclass, :instance) for which this instance cascades.

Returns:

  • (Array<Symbol,nil>)

    Contexts for which this Chain Proxy instance cascades.



509
510
511
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 509

def cascades_to
  @cascades_to
end

#contextsArray<Symbol,nil> (readonly)

Contexts (nil, :module, :class, :subclass, :instance) for which this instance is operative as a chain proxy.

Returns:

  • (Array<Symbol,nil>)

    Contexts for which this Chain Proxy instance is operative.



496
497
498
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 496

def contexts
  @contexts
end

#parent_hook_controllerObject (readonly)

Hook controller for which this instance is operative as a chaining proxy.



422
423
424
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 422

def parent_hook_controller
  @parent_hook_controller
end

Instance Method Details

#action {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that action should be performed at event hook in the context

specified this chained declaration.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



162
163
164
165
166
167
168
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 162

def action( & block )
  
  @index = @parent_hook_controller.action_at_index( @index, @cluster_name, @contexts, @cascades_to, true, & block )
  
  return self
  
end

#before_extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that chained actions should be inserted into the event stack after the location

in the same event stack where provided module(s) are specified to be extended.

Parameters:

  • module

    Module that insert should be after.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



346
347
348
349
350
351
352
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 346

def after_extend( *modules )

  @index = parent_hook_controller.highest_index( :extend, *modules ) + 1
  
  return self
  
end

#before_include {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that chained actions should be inserted into the event stack after the location

in the same event stack where provided module(s) are specified to be included.

Parameters:

  • module

    Module that insert should be after.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



320
321
322
323
324
325
326
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 320

def after_include( *modules )

  @index = parent_hook_controller.highest_index( :include, *modules ) + 1
  
  return self
  
end

#before_include_or_extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy Also known as: after_extend_or_include

Declare that chained actions should be inserted into the event stack after the location

in the same event stack where provided module(s) are specified to be included or extended.

Parameters:

  • module

    Module that insert should be after.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



373
374
375
376
377
378
379
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 373

def after_include_or_extend( *modules )
  
  @index = parent_hook_controller.highest_index( :include_or_extend, *modules ) + 1
  
  return self
  
end

#before_extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that chained actions should be inserted into the event stack prior to the location

in the same event stack where provided module(s) are specified to be extended.

Parameters:

  • module

    Module that insert should be prior to.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



239
240
241
242
243
244
245
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 239

def before_extend( *modules )
  
  @index = parent_hook_controller.lowest_index( :extend, *modules )
  
  return self
  
end

#before_include {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that chained actions should be inserted into the event stack prior to the location

in the same event stack where provided module(s) are specified to be included.

Parameters:

  • module

    Module that insert should be prior to.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



265
266
267
268
269
270
271
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 265

def before_include( *modules )
  
  @index = parent_hook_controller.lowest_index( :include, *modules )
  
  return self
  
end

#before_include_or_extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy Also known as: before_extend_or_include

Declare that chained actions should be inserted into the event stack prior to the location

in the same event stack where provided module(s) are specified to be included or extended.

Parameters:

  • module

    Module that insert should be prior to.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



292
293
294
295
296
297
298
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 292

def before_include_or_extend( *modules )

  @index = parent_hook_controller.lowest_index( :include_or_extend, *modules )
  
  return self
  
end

#cascade(context, ...) {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy Also known as: cascade_to

Declare contexts to which declarations made from this declaration chain should cascade.

Parameters:

  • context

    nil, :any, :class, :module, :subclass Contexts that should have event hooks cascaded into them.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 188

def cascade( *cascade_contexts, & block )

  case cascade_contexts.count

    when 0

      @cascades_to.clear
      @cascades_to.push( :any )

    when 1

      if cascade_contexts[ 0 ].nil?
        @cascades_to.clear
      else
        @cascades_to.replace( cascade_contexts )
      end

    else

      @cascades_to.replace( cascade_contexts )

  end
  
  if block_given?
    action( & block )
  end
  
  return self
  
end

#cluster_name(cluster_name) ⇒ Module::Cluster::InstanceController::ChainProxy

Set cluster name for which chained actions will be inserted in stack.

Returns:

  • (Module::Cluster::InstanceController::ChainProxy)

    Self.



458
459
460
461
462
463
464
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 458

def cluster_name( cluster_name )
  
  @cluster_name = cluster_name
  
  return self
  
end

#context(context, ...) ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Set context for matching instance to determine whether to perform chained actions in stack.

Parameters:

  • context

    nil, :any, :class, :module, :subclass Contexts that should have event hooks cascaded into them.

Returns:



396
397
398
399
400
401
402
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 396

def context( *contexts )
  
  @contexts.replace( contexts )
  
  return self
  
end

#extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that modules should be extended at event hook in the context specified this chained declaration.

Parameters:

  • module

    Module to extend at event hook in the context specified this chained declaration.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 70

def extend( *modules, & block )

  @index = @parent_hook_controller.extend_at_index( @index, 
                                                    @cluster_name, 
                                                    @contexts, 
                                                    @cascades_to, 
                                                    true, 
                                                    *modules, 
                                                    & block )

  return self

end

#extend_and_include {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that modules should be extended and included at event hook in the context

specified this chained declaration. Order is reversed from #include_and_extend.

Parameters:

  • module

    Module to extend and include at event hook in the context specified this chained declaration.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 134

def extend_and_include( *modules, & block )
  
  @index = @parent_hook_controller.extend_and_include_at_index( @index, 
                                                                @cluster_name, 
                                                                @contexts, 
                                                                @cascades_to, 
                                                                true, 
                                                                *modules, 
                                                                & block )

  return self
  
end

#include {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that modules should be included at event hook in the context specified this chained declaration.

Parameters:

  • module

    Module to include at event hook in the context specified this chained declaration.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



45
46
47
48
49
50
51
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 45

def include( *modules, & block )
  
  @parent_hook_controller.include_at_index( @index, @cluster_name, @contexts, @cascades_to, true, *modules, & block )

  return self
  
end

#include_and_extend {|hooked_instance| ... } ⇒ Module::Cluster::InstanceController::HookController::ChainProxy

Declare that modules should be included and extended at event hook in the context

specified this chained declaration. See also #extend_and_include.

Parameters:

  • module

    Module to include and extend at event hook in the context specified this chained declaration.

Yields:

  • (hooked_instance)

    Block for event hook action.

Yield Parameters:

  • hooked_instance

    Instance for which event hook is occurring. Equivalent to parameter for #included and #extended.

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 102

def include_and_extend( *modules, & block )
  
  @index = @parent_hook_controller.include_and_extend_at_index( @index, 
                                                                @cluster_name, 
                                                                @contexts, 
                                                                @cascades_to, 
                                                                true, 
                                                                *modules, 
                                                                & block )

  return self
  
end

#index(index) ⇒ Module::Cluster::InstanceController::ChainProxy

Set index where chained actions will be inserted in stack.

Returns:

  • (Module::Cluster::InstanceController::ChainProxy)

    Self.



477
478
479
480
481
482
483
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 477

def index( index )
  
  @index = index
  
  return self
  
end

#reset_stateModule::Cluster::InstanceController::ChainProxy

Reset internal state data so that proxy can be re-used for chaining in a new context.

Returns:

  • (Module::Cluster::InstanceController::ChainProxy)

    Self.



435
436
437
438
439
440
441
442
443
444
445
# File 'lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb', line 435

def reset_state
  
  @cluster_name = nil
  @index = -1

  @contexts.clear
  @cascades_to.clear
  
  return self
  
end