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 1/4] core_ext: move String enhancements out of rabbit; add Integer.ordinalize
Date Mon, 21 Mar 2011 22:45:37 GMT
On Sat, 2011-03-19 at 14:17 +0100, Michal Fojtik wrote:
> On Mar 19, 2011, at 1:03 AM, lutter@redhat.com wrote:
> 
> ACK, with small inline comment bellow.
>
> > From: David Lutterkort <lutter@redhat.com>
> > 
> > It is much cleaner to keep monkey patches to stock Ruby classes in a
> > separate place. That place is lib/deltacloud/core_ext
> > ---
> > server/deltacloud.rb                      |    2 +
> > server/lib/deltacloud/core_ext.rb         |   20 +++++++++++
> > server/lib/deltacloud/core_ext/integer.rb |   33 ++++++++++++++++++
> > server/lib/deltacloud/core_ext/string.rb  |   52 +++++++++++++++++++++++++++++
> > server/lib/sinatra/rabbit.rb              |   35 -------------------
> > 5 files changed, 107 insertions(+), 35 deletions(-)
> > create mode 100644 server/lib/deltacloud/core_ext.rb
> > create mode 100644 server/lib/deltacloud/core_ext/integer.rb
> > create mode 100644 server/lib/deltacloud/core_ext/string.rb
> > 
> > diff --git a/server/deltacloud.rb b/server/deltacloud.rb
> > index 83f7cfb..cd310ef 100644
> > diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb
> > new file mode 100644
> > index 0000000..2beba00
> > --- /dev/null
> > +++ b/server/lib/deltacloud/core_ext/string.rb
> > @@ -0,0 +1,52 @@
> > +
> > +class String
> > +  # Rails defines this for a number of other classes, including Object
> > +  # see activesupport/lib/active_support/core_ext/object/blank.rb
> > +  def blank?
> > +      self !~ /\S/
> > +  end
> > +
> > +  # Title case.
> > +  #
> > +  #   "this is a string".titlecase
> > +  #   => "This Is A String"
> > +  #
> > +  # CREDIT: Eliazar Parra
> > +  # Copied from facets
> > +  def titlecase
> > +    gsub(/\b\w/){ $`[-1,1] == "'" ? $& : $&.upcase }
> > +  end
> > +
> > +  def pluralize
> > +    self + "s"
> > +  end
> > +
> > +  def singularize
> > +    self.gsub(/s$/, '')
> > +  end
> 
> There was some special cases when this pluralization/singularization methods
> doesn't work. Collections like 'addresses', etc.

Yes, thre are - but they were not addressed in this code. The above is a
straight cut&paste from rabbit.rb; I'll commit as-is, if the lack of
rules is causing problems, we need to address that separately.

David



Mime
View raw message