Module: Phenomenal::AdaptationManagement

Included in:
Manager
Defined in:
lib/phenomenal/manager/adaptation_management.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active_adaptationsObject

Returns the value of attribute active_adaptations.



2
3
4
# File 'lib/phenomenal/manager/adaptation_management.rb', line 2

def active_adaptations
  @active_adaptations
end

#deployed_adaptationsObject

Returns the value of attribute deployed_adaptations.



2
3
4
# File 'lib/phenomenal/manager/adaptation_management.rb', line 2

def deployed_adaptations
  @deployed_adaptations
end

Instance Method Details

#proceed(calling_stack, instance, *args, &block) ⇒ Object

Call the old implementation of the method ‘caller.caller_method’



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/phenomenal/manager/adaptation_management.rb', line 21

def proceed(calling_stack,instance,*args,&block)
  calling_adaptation = find_adaptation(calling_stack)
  # IMPROVE Problems will appears if proceed called in a file where
  # adaptations are defined but not in one of them=> how to check?
  # IMPROVE Problems will also appears if two adaptations are defined on the 
  # same line using the ';' some check needed at add_adaptation ?
  adaptations_stack = sorted_adaptations_for(calling_adaptation.klass,  
    calling_adaptation.method_name,calling_adaptation.instance_adaptation?)
  calling_adaptation_index = adaptations_stack.find_index(calling_adaptation)
  next_adaptation = adaptations_stack[calling_adaptation_index+1]
  next_adaptation.bind(instance,*args, &block)
end

#register_adaptation(adaptation) ⇒ Object

Register a new adaptation for a registered context



5
6
7
8
9
10
11
12
13
# File 'lib/phenomenal/manager/adaptation_management.rb', line 5

def register_adaptation(adaptation)
  default_adaptation = default_feature.adaptations.find do|i| 
    i.concern?(adaptation.klass,adaptation.method_name,adaptation.instance_adaptation?)
  end
  if adaptation.context!=default_feature && !default_adaptation
    save_default_adaptation(adaptation.klass, adaptation.method_name,adaptation.instance_adaptation?)
  end
  activate_adaptation(adaptation) if adaptation.context.active?
end

#unregister_adaptation(adaptation) ⇒ Object

Unregister an adaptation for a registered context



16
17
18
# File 'lib/phenomenal/manager/adaptation_management.rb', line 16

def unregister_adaptation(adaptation)
  deactivate_adaptation(adaptation) if adaptation.context.active?
end