incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Lutterkort <lut...@redhat.com>
Subject Re: [PATCH 4/4] Tidying up of repetitive code into helper methods: extraction of blob metadata headers and renaming of the metadata header prefix ('X-Deltacloud-Blobmeta-KEY:VAL' ==> 'x-amz-meta-KEY:VAL') are now in a BlobHelper module (in /helpers/blob_stream.rb)
Date Thu, 09 Jun 2011 13:04:59 GMT
On Wed, 2011-06-08 at 20:09 +0300, marios@redhat.com wrote:
> From: marios <marios@redhat.com>
> 
> 
> Signed-off-by: marios <marios@redhat.com>
> ---
>  .../lib/deltacloud/drivers/azure/azure_driver.rb   |    2 +-
>  server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    4 ++--
>  server/lib/deltacloud/drivers/mock/mock_driver.rb  |   11 +++++------
>  .../drivers/rackspace/rackspace_driver.rb          |    4 ++--
>  server/lib/deltacloud/helpers/blob_stream.rb       |   18 ++++++++++++++++--
>  server/server.rb                                   |    6 ++----
>  6 files changed, 28 insertions(+), 17 deletions(-)

ACK. One small nit:

> diff --git a/server/lib/deltacloud/helpers/blob_stream.rb b/server/lib/deltacloud/helpers/blob_stream.rb
> index 440529b..c2f714c 100644
> --- a/server/lib/deltacloud/helpers/blob_stream.rb
> +++ b/server/lib/deltacloud/helpers/blob_stream.rb
> @@ -81,6 +81,21 @@ class Hash
>  
>  end
>  
> +module BlobHelper
> +
> +  def self.extract_blob_metadata_hash(env_hash)
> +    meta_array = env_hash.select{|k,v| k.match(/^HTTP[-_]X[-_]Deltacloud[-_]Blobmeta[-_]/i)}
> +    metadata = meta_array.inject({}){ |result, array| result[array.first.upcase] = array.last;
result}
> +    metadata
> +  end
> +
> +  #e.g. from HTTP-X-Deltacloud-Blobmeta-FOO:BAR to amz-meta-FOO:BAR
> +  def self.rename_metadata_headers(metadata, rename_to)
> +    metadata.gsub_keys('HTTP[-_]X[-_]Deltacloud[-_]Blobmeta[-_]', rename_to)
> +  end
> +
> +end

That ugly regexp should be defined as a constant; which points to an
oddity in the interface for Hash.gsub_keys: that should take a regexp,
not a string as its first argument.

David



Mime
View raw message