You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/07/27 00:58:40 UTC

Two small patches

Two small patches, one to make using require_relative easier on 1.8.x, and
one to setup bundler from the Rakefile. The latter means that we now
require bundler for development (and deployment) - that shouldn't be too
onerous a requirement at this stage.

David

Re: Two small patches

Posted by Michal Fojtik <mf...@redhat.com>.
Hi,

ACK both.

I was a bit concerned about bundler in Linux environment vs. RPM.
The bundler will fail to find the correct gems if they are not installed
in the system with correct version.

But then I realized, that 'rake' is really a devel tool and people will
use 'bundle' anyway. 

Michal Fojtik
http://deltacloud.org
mfojtik@redhat.com



On Jul 27, 2012, at 12:58 AM, lutter@redhat.com wrote:

> 
> Two small patches, one to make using require_relative easier on 1.8.x, and
> one to setup bundler from the Rakefile. The latter means that we now
> require bundler for development (and deployment) - that shouldn't be too
> onerous a requirement at this stage.
> 
> David


[PATCH 2/2] * server/Rakefile: setup bundler

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

---
 server/Rakefile |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/server/Rakefile b/server/Rakefile
index 41eb7fa..96a870d 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -21,6 +21,14 @@ require 'rake'
 require 'rake/testtask'
 require 'rubygems/package_task'
 
+begin
+  require "bundler"
+  Bundler.setup
+rescue LoadError
+  $stderr.puts "Please install bundler with 'gem install bundler'"
+  exit(1)
+end
+
 $top_srcdir = File.dirname(__FILE__)
 $:.unshift File.join($top_srcdir, 'lib')
 
-- 
1.7.7.6


[PATCH 1/2] Use require_relative gem instead of copies of the same boilerplate

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

We'll need a convenient way to use require_relative from many places,
especially test files. Copying the same boilerplate code all over the place
is too tedious for this - writing "require 'require_relative'" is much more
concise.
---
 server/deltacloud-core.gemspec    |    1 +
 server/lib/cimi/models.rb         |    8 +-------
 server/lib/deltacloud/api.rb      |    8 +-------
 server/lib/deltacloud/core_ext.rb |    8 +-------
 server/lib/deltacloud_rack.rb     |    8 +-------
 server/spec/spec_helper.rb        |    9 +--------
 server/tests/test_helper.rb       |    9 +--------
 7 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
index 9716427..25d31df 100644
--- a/server/deltacloud-core.gemspec
+++ b/server/deltacloud-core.gemspec
@@ -76,6 +76,7 @@ Gem::Specification.new do |s|
   s.add_dependency('net-ssh', '>= 2.0.0')
   s.add_dependency('thin', '>= 1.2.5')
   s.add_dependency('nokogiri', '>= 1.4.3')
+  s.add_dependency('require_relative')
 
 # dependencies for various cloud providers:
 # RHEV-M
diff --git a/server/lib/cimi/models.rb b/server/lib/cimi/models.rb
index 1214497..d88d4b8 100644
--- a/server/lib/cimi/models.rb
+++ b/server/lib/cimi/models.rb
@@ -17,13 +17,7 @@ module CIMI
   module Model; end
 end
 
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
+require 'require_relative'
 
 require_relative './models/schema'
 require_relative './models/base'
diff --git a/server/lib/deltacloud/api.rb b/server/lib/deltacloud/api.rb
index 2b520d4..9640764 100644
--- a/server/lib/deltacloud/api.rb
+++ b/server/lib/deltacloud/api.rb
@@ -16,13 +16,7 @@
 require 'rubygems'
 require 'ostruct'
 
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
+require 'require_relative'
 
 require_relative 'core_ext'
 require_relative 'models'
diff --git a/server/lib/deltacloud/core_ext.rb b/server/lib/deltacloud/core_ext.rb
index b448adb..7db0c16 100644
--- a/server/lib/deltacloud/core_ext.rb
+++ b/server/lib/deltacloud/core_ext.rb
@@ -14,13 +14,7 @@
 # under the License.
 #
 
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
+require 'require_relative'
 
 require_relative './core_ext/array'
 require_relative './core_ext/hash'
diff --git a/server/lib/deltacloud_rack.rb b/server/lib/deltacloud_rack.rb
index c30be3b..28b3045 100644
--- a/server/lib/deltacloud_rack.rb
+++ b/server/lib/deltacloud_rack.rb
@@ -13,13 +13,7 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
+require 'require_relative'
 
 require_relative './deltacloud/core_ext'
 require_relative './sinatra/rack_logger'
diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
index 47b8672..643873e 100644
--- a/server/spec/spec_helper.rb
+++ b/server/spec/spec_helper.rb
@@ -18,14 +18,7 @@ require 'rubygems'
 require 'pp'
 require 'rspec/core'
 require 'xmlsimple'
-
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
+require 'require_relative'
 
 require_relative '../lib/deltacloud/core_ext.rb'
 require_relative '../lib/cimi/models.rb'
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 5aed571..7fc1fb3 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -1,4 +1,5 @@
 require 'pp'
+require 'require_relative'
 
 ENV['RACK_ENV'] = 'test'
 
@@ -22,11 +23,3 @@ if ENV['COVERAGE']
     warn "To generate code coverage you need to install 'simplecov' (gem install simplecov OR bundle)"
   end
 end
-
-unless Kernel.respond_to?(:require_relative)
-  module Kernel
-    def require_relative(path)
-      require File.join(File.dirname(caller[0]), path.to_str)
-    end
-  end
-end
-- 
1.7.7.6