deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tong Li <liton...@us.ibm.com>
Subject Re: [PATCH] fix cloud entry point xml/json bugs caused by the collection changes
Date Thu, 13 Oct 2011 13:15:06 GMT
David,
	Please see the responses below on match.

Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com

David Lutterkort <lutter@redhat.com> wrote on 10/12/2011 06:28:12 PM:

> From: David Lutterkort <lutter@redhat.com>
> To: deltacloud-dev@incubator.apache.org
> Date: 10/12/2011 06:29 PM
> Subject: Re: [PATCH] fix cloud entry point xml/json bugs caused by
> the collection changes
>
> On Wed, 2011-10-12 at 13:10 -0700, email4tong@gmail.com wrote:
> > From: Tong Li <litong01@us.ibm.com>
> >
> > ---
> >  server/views/cimi/cloudEntryPoint/index.xml.haml |    7 +++----
> >  1 files changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/
> server/views/cimi/cloudEntryPoint/index.xml.haml
> > index a8f0fce..75c772a 100644
> > --- a/server/views/cimi/cloudEntryPoint/index.xml.haml
> > +++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
> > @@ -4,7 +4,6 @@
> >    %name cloud entry point
> >    %description cloud entry point
> >    %created= Time.new.getutc.to_s
> > -  - @all_apis.each do |api|
> > -    - if api != :cloudEntryPoint
> > -      - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
> > -      = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
> > \ No newline at end of file
> > +  - @collections.each do |api|
> > +    - res_name = api[0].to_s.gsub(/_[a-z]/) { |match| match
> [1].to_s.upcase }
>
> There's a little Ruby surprise for you: match[1] is actually an integer;
> and "ab"[1].to_s.upcase == "98"

used irb and run "ab"[1].to_s.upcase, I got "B" as I expected. This is
using Ruby

C:\Users\IBM_ADMIN>irb
irb(main):001:0> "ab"[1].to_s.upcase
=> "B"

Also, see the following code.

irb(main):005:0> "ab".gsub(/ab/) {|match| match[1].to_s.upcase}
=> "B"

irb(main):001:0> "machine_configurations".gsub(/_[a-z]/) { |match| match
[1].to_s.upcase }
=> "machineConfigurations"

The above both return what were expected. I do not think
"ab"[1].to_s.upcase will return "98" as the code executed showed different
results.

>
> Instead of your patch I am using the one below. I also rebased against
> the latest HEAD and updated the patch series at
> http://people.apache.org/~lutter/patches/dmtf/
>
> From 90c10d96d1265f8f3cc62e9420504299f2ac455d Mon Sep 17 00:00:00 2001
> From: Tong Li <litong01@us.ibm.com>
> Date: Wed, 12 Oct 2011 13:10:39 -0700
> Subject: [PATCH] fix cloud entry point xml/json bugs caused by the
collection
>  changes
>
>
> Signed-off-by: David Lutterkort <lutter@redhat.com>
> ---
>  server/lib/deltacloud/core_ext/string.rb         |    5 +++
>  server/tests/core_ext/string.rb                  |   31 +++++++++++
> +++++++++++
>  server/views/cimi/cloudEntryPoint/index.xml.haml |    7 ++---
>  3 files changed, 39 insertions(+), 4 deletions(-)
>  create mode 100644 server/tests/core_ext/string.rb
>
> diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/
> deltacloud/core_ext/string.rb
> index 42fbad0..1cd79a0 100644
> --- a/server/lib/deltacloud/core_ext/string.rb
> +++ b/server/lib/deltacloud/core_ext/string.rb
> @@ -49,4 +49,9 @@ class String
>            tr("-", "_").
>            downcase
>    end
> +
> +
> +  def camelize
> +    gsub(/_[a-z]/) { |match| match[1].chr.upcase }
> +  end
>  end
> diff --git a/server/tests/core_ext/string.rb
b/server/tests/core_ext/string.rb
> new file mode 100644
> index 0000000..dfa57dc
> --- /dev/null
> +++ b/server/tests/core_ext/string.rb
> @@ -0,0 +1,31 @@
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.
The
> +# ASF licenses this file to you under the Apache License, Version 2.0
(the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See
the
> +# License for the specific language governing permissions and
limitations
> +# under the License.
> +#
> +
> +$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', '..')
> +require 'tests/common'
> +
> +require 'deltacloud/drivers'
> +require 'deltacloud/drivers/mock/mock_driver'
> +
> +module DeltacloudUnitTest
> +
> +  class StringTest < Test::Unit::TestCase
> +    def test_camelize
> +      "hello_camel".camelize.should == "helloCamel"
> +      "hello_camel_lots_of_humps".camelize.should ==
"helloCamelLotsOfHumps"
> +    end
> +  end
> +end
> diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/
> server/views/cimi/cloudEntryPoint/index.xml.haml
> index a8f0fce..c39a34d 100644
> --- a/server/views/cimi/cloudEntryPoint/index.xml.haml
> +++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
> @@ -4,7 +4,6 @@
>    %name cloud entry point
>    %description cloud entry point
>    %created= Time.new.getutc.to_s
> -  - @all_apis.each do |api|
> -    - if api != :cloudEntryPoint
> -      - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
> -      = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
> \ No newline at end of file
> +  - @collections.each do |api|
> +    - res_name = api[0].to_s.camelize
> +    = "<#{res_name} href=\"#{api[1]}\"/>"
> --
> 1.7.6.4
>
>
>

I've run more tests and they all work as expected. Can we commit?

Thanks.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message