Class: Phenomenal::Adaptation
- Inherits:
-
Object
- Object
- Phenomenal::Adaptation
- Defined in:
- lib/phenomenal/context/adaptation.rb
Overview
Represent a method adaptation for a particular context
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#implementation ⇒ Object
Returns the value of attribute implementation.
-
#instance_adaptation ⇒ Object
(also: #instance_adaptation?)
Returns the value of attribute instance_adaptation.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#src_file ⇒ Object
Returns the value of attribute src_file.
-
#src_line ⇒ Object
Returns the value of attribute src_line.
Instance Method Summary collapse
-
#bind(instance, *args, &block) ⇒ Object
Bind the implementation corresponding to this adaptation to ‘instance’ when instance_adaptation or to implementation class when class method.
-
#concern?(klass, method_name, instance_adaptation) ⇒ Boolean
True if the adaptation concern the class n_klass and method n_method.
-
#deploy ⇒ Object
Deploy actually the adaptation in the target class by overriding the current implementation.
-
#initialize(context, klass, method_name, instance_adapatation, implementation) ⇒ Adaptation
constructor
A new instance of Adaptation.
-
#to_s ⇒ Object
String representation.
Constructor Details
#initialize(context, klass, method_name, instance_adapatation, implementation) ⇒ Adaptation
Returns a new instance of Adaptation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phenomenal/context/adaptation.rb', line 7 def initialize(context,klass, method_name,instance_adapatation,implementation) @context = context @klass = klass @method_name = method_name @implementation = implementation @instance_adaptation=instance_adapatation check_validity # Save the source location if any, this is used to find again the adaptation # in a proceed call. It always exists except for method directly # implemented in C -> Not a problem because these one never use proceed source_location = implementation.source_location if source_location @src_file = implementation.source_location[0] @src_line = implementation.source_location[1] end end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def context @context end |
#implementation ⇒ Object
Returns the value of attribute implementation.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def implementation @implementation end |
#instance_adaptation ⇒ Object Also known as: instance_adaptation?
Returns the value of attribute instance_adaptation.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def instance_adaptation @instance_adaptation end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def klass @klass end |
#method_name ⇒ Object
Returns the value of attribute method_name.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def method_name @method_name end |
#src_file ⇒ Object
Returns the value of attribute src_file.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def src_file @src_file end |
#src_line ⇒ Object
Returns the value of attribute src_line.
3 4 5 |
# File 'lib/phenomenal/context/adaptation.rb', line 3 def src_line @src_line end |
Instance Method Details
#bind(instance, *args, &block) ⇒ Object
Bind the implementation corresponding to this adaptation to ‘instance’ when instance_adaptation or to implementation class when class method
38 39 40 41 42 43 44 45 |
# File 'lib/phenomenal/context/adaptation.rb', line 38 def bind(instance,*args,&block) target = instance_adaptation? ? instance : klass if implementation.is_a?(Proc) bind_proc(target,*args,&block) else bind_method(target,*args,&block) end end |
#concern?(klass, method_name, instance_adaptation) ⇒ Boolean
True if the adaptation concern the class n_klass and method n_method
48 49 50 51 52 |
# File 'lib/phenomenal/context/adaptation.rb', line 48 def concern?(klass,method_name,instance_adaptation) self.klass==klass && self.method_name==method_name && self.instance_adaptation==instance_adaptation end |
#deploy ⇒ Object
Deploy actually the adaptation in the target class by overriding the current implementation
26 27 28 29 30 31 32 33 34 |
# File 'lib/phenomenal/context/adaptation.rb', line 26 def deploy method_name = self.method_name implementation = self.implementation if instance_adaptation? klass.class_eval { define_method(method_name, implementation) } else klass.define_singleton_method(method_name,implementation) end end |
#to_s ⇒ Object
String representation
55 56 57 |
# File 'lib/phenomenal/context/adaptation.rb', line 55 def to_s ":#{context.name} => #{klass.name}.#{method_name} :: #{src_file}:#{src_line}" end |