deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/2] Core: Get rid of using 'load' method
Date Fri, 20 Jul 2012 11:35:59 GMT
From: Michal Fojtik <mfojtik@redhat.com>

The load method should be replaced and forbidden everywhere,
since it 'reload' the source code even if it is already required.
This cause many 'already defined' errors.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/Rakefile                                              |    2 +-
 server/lib/deltacloud/api.rb                                 |   10 +++++++++-
 server/lib/deltacloud_rack.rb                                |    2 +-
 server/tests/deltacloud/base_collection_test.rb              |    3 +--
 .../tests/deltacloud/collections/buckets_collection_test.rb  |    3 +--
 .../tests/deltacloud/collections/drivers_collection_test.rb  |    3 +--
 .../tests/deltacloud/collections/images_collection_test.rb   |    3 +--
 .../collections/instance_states_collection_test.rb           |    3 +--
 .../deltacloud/collections/instances_collection_test.rb      |    3 +--
 server/tests/deltacloud/collections_test.rb                  |    3 +--
 server/tests/deltacloud/common.rb                            |    2 +-
 server/tests/deltacloud/deltacloud_helper_test.rb            |    2 +-
 server/tests/deltacloud/drivers_test.rb                      |    3 +--
 server/tests/deltacloud/rack_test.rb                         |    2 +-
 server/tests/deltacloud/server_test.rb                       |    3 +--
 server/tests/drivers/base/base_driver_test.rb                |    3 +--
 server/tests/drivers/models/address_test.rb                  |    4 ++--
 server/tests/drivers/models/base_test.rb                     |    3 +--
 server/tests/drivers/models/blob_test.rb                     |    4 ++--
 server/tests/drivers/models/hardware_profile_test.rb         |    4 ++--
 server/tests/drivers/models/instance_profile_test.rb         |    4 ++--
 server/tests/drivers/models/instance_test.rb                 |    4 ++--
 server/tests/drivers/models/keys_test.rb                     |    4 ++--
 server/tests/drivers/models/metrics_test.rb                  |    4 ++--
 server/tests/helpers/core_ext/array_test.rb                  |    2 +-
 server/tests/helpers/core_ext/hash_test.rb                   |    2 +-
 server/tests/helpers/core_ext/integer_test.rb                |    2 +-
 server/tests/helpers/core_ext/string_test.rb                 |    2 +-
 server/tests/test_helper.rb                                  |    9 ++++++++-
 29 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/server/Rakefile b/server/Rakefile
index bc84c96..2b5a2b8 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -20,7 +20,6 @@
 require 'rake'
 require 'rake/testtask'
 require 'rubygems/package_task'
-load File.join(File.dirname(__FILE__), 'config.ru')
 
 $top_srcdir = File.dirname(__FILE__)
 $:.unshift File.join($top_srcdir, 'lib')
@@ -80,6 +79,7 @@ end
 
 desc "List the routes defined by Rabbit"
 task :routes do
+  load File.join(File.dirname(__FILE__), 'config.ru')
   Deltacloud.collections.each do |c|
     puts "\033[1;32;m#{c.name}\33[0m"
     c.operations.each do |o|
diff --git a/server/lib/deltacloud/api.rb b/server/lib/deltacloud/api.rb
index a2ca7ab..2b520d4 100644
--- a/server/lib/deltacloud/api.rb
+++ b/server/lib/deltacloud/api.rb
@@ -16,7 +16,15 @@
 require 'rubygems'
 require 'ostruct'
 
-load File.join(File.dirname(__FILE__), 'core_ext.rb')
+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_relative 'core_ext'
 require_relative 'models'
 require_relative 'drivers'
 require_relative 'helpers/driver_helper'
diff --git a/server/lib/deltacloud_rack.rb b/server/lib/deltacloud_rack.rb
index 3b609ed..c30be3b 100644
--- a/server/lib/deltacloud_rack.rb
+++ b/server/lib/deltacloud_rack.rb
@@ -42,7 +42,7 @@ module Deltacloud
 
   def self.require_frontend!(frontend=:deltacloud)
     frontend = frontend.to_sym
-    load File.join(File.dirname(__FILE__), frontend.to_s, 'server.rb')
+    require_relative File.join(frontend.to_s, 'server.rb')
     Deltacloud[frontend].klass eval('::'+Deltacloud[frontend].klass)
   end
 
diff --git a/server/tests/deltacloud/base_collection_test.rb b/server/tests/deltacloud/base_collection_test.rb
index 2f390c3..3e820d6 100644
--- a/server/tests/deltacloud/base_collection_test.rb
+++ b/server/tests/deltacloud/base_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud::Collections::Base do
 
diff --git a/server/tests/deltacloud/collections/buckets_collection_test.rb b/server/tests/deltacloud/collections/buckets_collection_test.rb
index 6eff7ad..9b4a40c 100644
--- a/server/tests/deltacloud/collections/buckets_collection_test.rb
+++ b/server/tests/deltacloud/collections/buckets_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', 'common.rb')
+require_relative File.join('..', 'common.rb')
 
 describe Deltacloud::Collections::Buckets do
 
diff --git a/server/tests/deltacloud/collections/drivers_collection_test.rb b/server/tests/deltacloud/collections/drivers_collection_test.rb
index 4467b68..e037ae1 100644
--- a/server/tests/deltacloud/collections/drivers_collection_test.rb
+++ b/server/tests/deltacloud/collections/drivers_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', 'common.rb')
+require_relative File.join('..', 'common.rb')
 
 describe Deltacloud::Collections::Drivers do
 
diff --git a/server/tests/deltacloud/collections/images_collection_test.rb b/server/tests/deltacloud/collections/images_collection_test.rb
index 8262df8..de105c9 100644
--- a/server/tests/deltacloud/collections/images_collection_test.rb
+++ b/server/tests/deltacloud/collections/images_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', 'common.rb')
+require_relative File.join('..', 'common.rb')
 
 describe Deltacloud::Collections::Images do
 
diff --git a/server/tests/deltacloud/collections/instance_states_collection_test.rb b/server/tests/deltacloud/collections/instance_states_collection_test.rb
index ecf86c5..bfcf7c9 100644
--- a/server/tests/deltacloud/collections/instance_states_collection_test.rb
+++ b/server/tests/deltacloud/collections/instance_states_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', 'common.rb')
+require_relative File.join('..', 'common.rb')
 
 describe Deltacloud::Collections::InstanceStates do
 
diff --git a/server/tests/deltacloud/collections/instances_collection_test.rb b/server/tests/deltacloud/collections/instances_collection_test.rb
index a1da030..abaf571 100644
--- a/server/tests/deltacloud/collections/instances_collection_test.rb
+++ b/server/tests/deltacloud/collections/instances_collection_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', 'common.rb')
+require_relative File.join('..', 'common.rb')
 
 describe Deltacloud::Collections::Instances do
 
diff --git a/server/tests/deltacloud/collections_test.rb b/server/tests/deltacloud/collections_test.rb
index f010603..2d15c61 100644
--- a/server/tests/deltacloud/collections_test.rb
+++ b/server/tests/deltacloud/collections_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud do
 
diff --git a/server/tests/deltacloud/common.rb b/server/tests/deltacloud/common.rb
index b28f82d..7ba3ec3 100644
--- a/server/tests/deltacloud/common.rb
+++ b/server/tests/deltacloud/common.rb
@@ -3,7 +3,7 @@ require 'rack/test'
 require 'nokogiri'
 require 'pp'
 
-load File.join(File.dirname(__FILE__), '..', '..', 'lib', 'deltacloud_rack.rb')
+require_relative File.join('..', '..', 'lib', 'deltacloud_rack.rb')
 
 include Rack::Test::Methods
 
diff --git a/server/tests/deltacloud/deltacloud_helper_test.rb b/server/tests/deltacloud/deltacloud_helper_test.rb
index 9096db0..88c5ebb 100644
--- a/server/tests/deltacloud/deltacloud_helper_test.rb
+++ b/server/tests/deltacloud/deltacloud_helper_test.rb
@@ -1,5 +1,5 @@
 require 'minitest/autorun'
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud::Helpers::Application do
 
diff --git a/server/tests/deltacloud/drivers_test.rb b/server/tests/deltacloud/drivers_test.rb
index 90d96ac..3c21981 100644
--- a/server/tests/deltacloud/drivers_test.rb
+++ b/server/tests/deltacloud/drivers_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud::Drivers do
 
diff --git a/server/tests/deltacloud/rack_test.rb b/server/tests/deltacloud/rack_test.rb
index d550c7c..34665f5 100644
--- a/server/tests/deltacloud/rack_test.rb
+++ b/server/tests/deltacloud/rack_test.rb
@@ -1,5 +1,5 @@
 require 'minitest/autorun'
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud do
 
diff --git a/server/tests/deltacloud/server_test.rb b/server/tests/deltacloud/server_test.rb
index b97a286..811a3ff 100644
--- a/server/tests/deltacloud/server_test.rb
+++ b/server/tests/deltacloud/server_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), 'common.rb')
+require_relative 'common.rb'
 
 describe Deltacloud::API do
 
diff --git a/server/tests/drivers/base/base_driver_test.rb b/server/tests/drivers/base/base_driver_test.rb
index 4173b50..074c415 100644
--- a/server/tests/drivers/base/base_driver_test.rb
+++ b/server/tests/drivers/base/base_driver_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'drivers',
'base_driver.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'drivers', 'base_driver.rb')
 
 describe Deltacloud::BaseDriver do
 
diff --git a/server/tests/drivers/models/address_test.rb b/server/tests/drivers/models/address_test.rb
index eae9a02..34a6a5f 100644
--- a/server/tests/drivers/models/address_test.rb
+++ b/server/tests/drivers/models/address_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
 
 describe Address do
 
diff --git a/server/tests/drivers/models/base_test.rb b/server/tests/drivers/models/base_test.rb
index 4ac71e4..a1cc873 100644
--- a/server/tests/drivers/models/base_test.rb
+++ b/server/tests/drivers/models/base_test.rb
@@ -1,6 +1,5 @@
 require 'minitest/autorun'
-
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
 
 describe BaseModel do
 
diff --git a/server/tests/drivers/models/blob_test.rb b/server/tests/drivers/models/blob_test.rb
index eae9a02..34a6a5f 100644
--- a/server/tests/drivers/models/blob_test.rb
+++ b/server/tests/drivers/models/blob_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'address.rb')
 
 describe Address do
 
diff --git a/server/tests/drivers/models/hardware_profile_test.rb b/server/tests/drivers/models/hardware_profile_test.rb
index 8e65dfd..4f01e67 100644
--- a/server/tests/drivers/models/hardware_profile_test.rb
+++ b/server/tests/drivers/models/hardware_profile_test.rb
@@ -2,8 +2,8 @@ require 'minitest/autorun'
 require 'sinatra/base'
 require 'sinatra/rabbit'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'hardware_profile.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'hardware_profile.rb')
 
 describe Deltacloud::HardwareProfile do
 
diff --git a/server/tests/drivers/models/instance_profile_test.rb b/server/tests/drivers/models/instance_profile_test.rb
index 7f343c7..6f5071e 100644
--- a/server/tests/drivers/models/instance_profile_test.rb
+++ b/server/tests/drivers/models/instance_profile_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'instance_profile.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'instance_profile.rb')
 
 describe InstanceProfile do
 
diff --git a/server/tests/drivers/models/instance_test.rb b/server/tests/drivers/models/instance_test.rb
index 005b72b..62ca33b 100644
--- a/server/tests/drivers/models/instance_test.rb
+++ b/server/tests/drivers/models/instance_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'instance.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'instance.rb')
 
 describe Instance do
 
diff --git a/server/tests/drivers/models/keys_test.rb b/server/tests/drivers/models/keys_test.rb
index a4ddeb5..befc4bb 100644
--- a/server/tests/drivers/models/keys_test.rb
+++ b/server/tests/drivers/models/keys_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'key.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'key.rb')
 
 describe Key do
 
diff --git a/server/tests/drivers/models/metrics_test.rb b/server/tests/drivers/models/metrics_test.rb
index 255d0e6..be8c581 100644
--- a/server/tests/drivers/models/metrics_test.rb
+++ b/server/tests/drivers/models/metrics_test.rb
@@ -1,7 +1,7 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'models', 'metric.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'base_model.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'models', 'metric.rb')
 
 describe Metric do
 
diff --git a/server/tests/helpers/core_ext/array_test.rb b/server/tests/helpers/core_ext/array_test.rb
index c116484..a228bd5 100644
--- a/server/tests/helpers/core_ext/array_test.rb
+++ b/server/tests/helpers/core_ext/array_test.rb
@@ -1,6 +1,6 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
 
 class TestArray < MiniTest::Unit::TestCase
 
diff --git a/server/tests/helpers/core_ext/hash_test.rb b/server/tests/helpers/core_ext/hash_test.rb
index 5eccdeb..d87042b 100644
--- a/server/tests/helpers/core_ext/hash_test.rb
+++ b/server/tests/helpers/core_ext/hash_test.rb
@@ -1,6 +1,6 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
 
 class TestHash < MiniTest::Unit::TestCase
 
diff --git a/server/tests/helpers/core_ext/integer_test.rb b/server/tests/helpers/core_ext/integer_test.rb
index b4d50f6..5dd60f5 100644
--- a/server/tests/helpers/core_ext/integer_test.rb
+++ b/server/tests/helpers/core_ext/integer_test.rb
@@ -1,6 +1,6 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
 
 class TestInteger < MiniTest::Unit::TestCase
 
diff --git a/server/tests/helpers/core_ext/string_test.rb b/server/tests/helpers/core_ext/string_test.rb
index 89eeaa4..cc9a349 100644
--- a/server/tests/helpers/core_ext/string_test.rb
+++ b/server/tests/helpers/core_ext/string_test.rb
@@ -1,6 +1,6 @@
 require 'minitest/autorun'
 
-load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'core_ext.rb')
 
 class TestString < MiniTest::Unit::TestCase
 
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 3bbd6a3..0f9b64a 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -1,4 +1,3 @@
-
 %x[rake mock:fixtures:reset]
 
 if ENV['COVERAGE']
@@ -19,3 +18,11 @@ 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.10.2


Mime
View raw message