Module: Phenomenal::ContextManagement
- Included in:
- Manager
- Defined in:
- lib/phenomenal/manager/context_management.rb
Instance Attribute Summary collapse
-
#combined_contexts ⇒ Object
Returns the value of attribute combined_contexts.
-
#contexts ⇒ Object
Returns the value of attribute contexts.
-
#default_feature ⇒ Object
Returns the value of attribute default_feature.
-
#shared_contexts ⇒ Object
Returns the value of attribute shared_contexts.
Instance Method Summary collapse
-
#activate_context(context) ⇒ Object
Activate the context ‘context’ and deploy the related adaptation.
-
#context_defined?(context, *contexts) ⇒ Boolean
Check wether context ‘context’ (or combined context) exist in the context manager.
-
#deactivate_context(context) ⇒ Object
Deactivate the adaptations (undeploy if needed).
-
#find_context(context, *contexts) ⇒ Object
Return the corresponding context (or combined context) or raise an error if the context isn’t currently registered.
-
#register_context(context) ⇒ Object
Register a new context.
-
#unregister_context(context) ⇒ Object
Unregister a context (forget).
Instance Attribute Details
#combined_contexts ⇒ Object
Returns the value of attribute combined_contexts.
2 3 4 |
# File 'lib/phenomenal/manager/context_management.rb', line 2 def combined_contexts @combined_contexts end |
#contexts ⇒ Object
Returns the value of attribute contexts.
2 3 4 |
# File 'lib/phenomenal/manager/context_management.rb', line 2 def contexts @contexts end |
#default_feature ⇒ Object
Returns the value of attribute default_feature.
2 3 4 |
# File 'lib/phenomenal/manager/context_management.rb', line 2 def default_feature @default_feature end |
#shared_contexts ⇒ Object
Returns the value of attribute shared_contexts.
2 3 4 |
# File 'lib/phenomenal/manager/context_management.rb', line 2 def shared_contexts @shared_contexts end |
Instance Method Details
#activate_context(context) ⇒ Object
Activate the context ‘context’ and deploy the related adaptation
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/phenomenal/manager/context_management.rb', line 40 def activate_context(context) begin # Relationships managment rmanager.activate_relationships(context) if context.just_activated? # Activation of adaptations context.adaptations.each{ |i| activate_adaptation(i) } # Activate combined contexts activate_combined_contexts(context) rescue Phenomenal::Error context.deactivate # rollback the deployed adaptations raise # throw up the exception end end |
#context_defined?(context, *contexts) ⇒ Boolean
Check wether context ‘context’ (or combined context) exist in the context manager. Context can be either the context name or the context instance itself. Return the context if found, or nil otherwise
82 83 84 85 86 87 88 89 90 |
# File 'lib/phenomenal/manager/context_management.rb', line 82 def context_defined?(context, *contexts) c=nil begin c = find_context(context,*contexts) rescue Phenomenal::Error return nil end return c end |
#deactivate_context(context) ⇒ Object
Deactivate the adaptations (undeploy if needed)
55 56 57 58 59 60 61 62 63 |
# File 'lib/phenomenal/manager/context_management.rb', line 55 def deactivate_context(context) #Relationships managment rmanager.deactivate_relationships(context) #Adaptations deactivation context.adaptations.each do |i| deactivate_adaptation(i) end deactivate_combined_contexts(context) end |
#find_context(context, *contexts) ⇒ Object
Return the corresponding context (or combined context) or raise an error if the context isn’t currently registered. The ‘context’ parameter can be either a reference to a context instance or a Symbol with the name of a named (not anonymous) context.
69 70 71 72 73 74 75 76 |
# File 'lib/phenomenal/manager/context_management.rb', line 69 def find_context(context, *contexts) if contexts.length==0 find_simple_context(context) else #Combined contexts contexts.insert(0,context) find_combined_context(contexts) end end |
#register_context(context) ⇒ Object
Register a new context
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/phenomenal/manager/context_management.rb', line 5 def register_context(context) if context_defined?(context) raise(Phenomenal::Error, "The context #{context} is already registered" ) end if context.name && context_defined?(context.name) raise(Phenomenal::Error, "There is already a context with name: #{context.name}." + " If you want to have named context it has to be a globally unique name" ) end # Update the relationships that concern this context rmanager.update_relationships_references(context) # Store the context at its ID contexts[context]=context end |
#unregister_context(context) ⇒ Object
Unregister a context (forget)
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/phenomenal/manager/context_management.rb', line 24 def unregister_context(context) if context==default_feature && contexts.size>1 raise(Phenomenal::Error, "Default feature can only be forgotten when alone" ) else contexts.delete(context) unregister_combined_contexts(context) # Restore default feature init_default() if context==default_feature end end |