deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH core] CIMI: Fixed incompatibility between 1.9 and 1.8 in Proc callback
Date Wed, 18 Jan 2012 09:25:27 GMT
On Jan 18, 2012, at 10:03 AM, marios@redhat.com wrote:

> ack
> 
> that does it :)

Thanks! Pushed.

 -- Michal

> 
> 13 scenarios (13 passed)
> 61 steps (61 passed)
> 0m0.426s
> 
> 
> On 17/01/12 18:15, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mfojtik@redhat.com>
>> 
>> 
>> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
>> ---
>> server/lib/deltacloud/core_ext/proc.rb |   20 ++++++++++++--------
>> 1 files changed, 12 insertions(+), 8 deletions(-)
>> 
>> diff --git a/server/lib/deltacloud/core_ext/proc.rb b/server/lib/deltacloud/core_ext/proc.rb
>> index 3c443ff..1917123 100644
>> --- a/server/lib/deltacloud/core_ext/proc.rb
>> +++ b/server/lib/deltacloud/core_ext/proc.rb
>> @@ -13,15 +13,19 @@
>> # License for the specific language governing permissions and limitations
>> # under the License.
>> 
>> -# Original code copied from: http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
>> -# Copyright 2011 Matt Sears.
>> +# Original code copied from https://gist.github.com/1417762
>> +# Copyright 2011 Emmanuel Oga.
>> +
>> class Proc
>> +
>> +  Callback = Struct.new(:called, :args) do
>> +    def method_missing(name, *)
>> +      name == :"#{called}?" || (name == called && block_given? &&
yield(*args))
>> +    end
>> +  end
>> +
>>   def callback(callable, *args)
>> -    self === Class.new do
>> -      method_name = callable.to_sym
>> -      define_method(method_name) { |&block| block.nil? ? true : block.call(*args)
}
>> -      define_method("#{method_name}?") { true }
>> -      def method_missing(method_name, *args, &block) false; end
>> -    end.new
>> +    call Callback.new(callable, *args)
>>   end
>> +
>> end
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Mime
View raw message