tidy up requires

It's really ugly to have to keep repeating File.dirname(__FILE__),
so we use a temporary variable, even in the case of a single require.
This minimises long "requires" lines and "requires" statements with
needing line-breaks, and should make search-and-replace a bit easier
if we later want to migrate to __dir__ (Ruby >= 2.0) or require_relative.

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both

I've deliberately rejected the pattern:

  require File.expand_path('../relative/path', __FILE__)

because it relies on inconsistent semantics and inconsistent
documentation in File.expand_path:

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both#comment34147297_4333552
This commit is contained in:
Adam Spiers
2014-03-22 14:09:43 +00:00
parent bb280de1e0
commit c0e3907ba0
33 changed files with 112 additions and 87 deletions

View File

@@ -1,2 +1,3 @@
require File.expand_path('pacemaker/standard_cib_object.rb', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('pacemaker/runnable_resource.rb', File.dirname(__FILE__)) require File.expand_path('pacemaker/standard_cib_object.rb', this_dir)
require File.expand_path('pacemaker/runnable_resource.rb', this_dir)

View File

@@ -1,4 +1,4 @@
require ::File.expand_path('standard_cib_object', ::File.dirname(__FILE__)) require ::File.expand_path('standard_cib_object', File.dirname(__FILE__))
# Common code used by Pacemaker LWRP providers for resources supporting # Common code used by Pacemaker LWRP providers for resources supporting
# the :run action. # the :run action.

View File

@@ -1,5 +1,5 @@
require ::File.expand_path('../../../pacemaker/cib_object', require ::File.expand_path('../../../pacemaker/cib_object',
::File.dirname(__FILE__)) File.dirname(__FILE__))
# Common code used by Pacemaker LWRP providers # Common code used by Pacemaker LWRP providers

View File

@@ -1,5 +1,6 @@
require File.expand_path('../resource', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__)) require File.expand_path('../resource', this_dir)
require File.expand_path('../mixins/resource_meta', this_dir)
class Pacemaker::Resource::Clone < Pacemaker::Resource class Pacemaker::Resource::Clone < Pacemaker::Resource
TYPE = 'clone' TYPE = 'clone'

View File

@@ -1,5 +1,6 @@
require File.expand_path('../resource', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__)) require File.expand_path('../resource', this_dir)
require File.expand_path('../mixins/resource_meta', this_dir)
class Pacemaker::Resource::Group < Pacemaker::Resource class Pacemaker::Resource::Group < Pacemaker::Resource
TYPE = 'group' TYPE = 'group'

View File

@@ -1,6 +1,8 @@
require 'shellwords' require 'shellwords'
require File.expand_path('../resource', File.dirname(__FILE__))
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../resource', this_dir)
require File.expand_path('../mixins/resource_meta', this_dir)
class Pacemaker::Resource::Primitive < Pacemaker::Resource class Pacemaker::Resource::Primitive < Pacemaker::Resource
TYPE = 'primitive' TYPE = 'primitive'

View File

@@ -17,9 +17,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::RunnableResource include Chef::Mixin::Pacemaker::RunnableResource

View File

@@ -17,9 +17,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::StandardCIBObject include Chef::Mixin::Pacemaker::StandardCIBObject

View File

@@ -16,9 +16,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::RunnableResource include Chef::Mixin::Pacemaker::RunnableResource

View File

@@ -17,9 +17,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::StandardCIBObject include Chef::Mixin::Pacemaker::StandardCIBObject

View File

@@ -17,9 +17,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::RunnableResource include Chef::Mixin::Pacemaker::RunnableResource

View File

@@ -17,9 +17,9 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker', ::File.dirname(__FILE__)) this_dir = ::File.dirname(__FILE__)
require ::File.expand_path('../libraries/chef/mixin/pacemaker', require ::File.expand_path('../libraries/pacemaker', this_dir)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/chef/mixin/pacemaker', this_dir)
include Chef::Mixin::Pacemaker::RunnableResource include Chef::Mixin::Pacemaker::RunnableResource

View File

@@ -17,8 +17,8 @@
# limitations under the License. # limitations under the License.
# #
require ::File.expand_path('../libraries/pacemaker/cib_object', this_dir = ::File.dirname(__FILE__)
::File.dirname(__FILE__)) require ::File.expand_path('../libraries/pacemaker/cib_object', this_dir)
action :create do action :create do
name = new_resource.name name = new_resource.name

View File

@@ -1,5 +1,5 @@
require ::File.expand_path('../../libraries/pacemaker/constraint/colocation', require ::File.expand_path('../../libraries/pacemaker/constraint/colocation',
::File.dirname(__FILE__)) File.dirname(__FILE__))
module Chef::RSpec module Chef::RSpec
module Pacemaker module Pacemaker

View File

@@ -1,5 +1,5 @@
require ::File.expand_path('../../libraries/pacemaker/resource/primitive', require ::File.expand_path('../../libraries/pacemaker/resource/primitive',
::File.dirname(__FILE__)) File.dirname(__FILE__))
module Chef::RSpec module Chef::RSpec
module Pacemaker module Pacemaker

View File

@@ -1,5 +1,5 @@
require ::File.expand_path('../../libraries/pacemaker/constraint/location', require ::File.expand_path('../../libraries/pacemaker/constraint/location',
::File.dirname(__FILE__)) File.dirname(__FILE__))
module Chef::RSpec module Chef::RSpec
module Pacemaker module Pacemaker

View File

@@ -2,8 +2,8 @@
require 'mixlib/shellout' require 'mixlib/shellout'
require File.expand_path('../../libraries/pacemaker/cib_object', this_dir = File.dirname(__FILE__)
File.dirname(__FILE__)) require File.expand_path('../../libraries/pacemaker/cib_object', this_dir)
module Chef::RSpec module Chef::RSpec
module Pacemaker module Pacemaker

View File

@@ -1,6 +1,7 @@
# Shared code used to test providers of CIB objects # Shared code used to test providers of CIB objects
require File.expand_path('../helpers/cib_object', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/cib_object', this_dir)
shared_context "a Pacemaker LWRP" do shared_context "a Pacemaker LWRP" do
before(:each) do before(:each) do

View File

@@ -3,7 +3,8 @@
# for primitives is runnable (since primitives can be started # for primitives is runnable (since primitives can be started
# and stopped) but constraints cannot. # and stopped) but constraints cannot.
require File.expand_path('../helpers/provider', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/provider', this_dir)
shared_examples "a runnable resource" do |fixture| shared_examples "a runnable resource" do |fixture|
def expect_running(running) def expect_running(running)

View File

@@ -1,8 +1,10 @@
require 'spec_helper'
require 'mixlib/shellout' require 'mixlib/shellout'
require File.expand_path('../../../libraries/pacemaker', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../../fixtures/keystone_primitive', File.dirname(__FILE__))
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../libraries/pacemaker', this_dir)
require File.expand_path('../../fixtures/keystone_primitive', this_dir)
describe Pacemaker::CIBObject do describe Pacemaker::CIBObject do

View File

@@ -1,8 +1,10 @@
require 'spec_helper' require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../../libraries/pacemaker/constraint/colocation', require File.expand_path('../../../../libraries/pacemaker/constraint/colocation',
File.dirname(__FILE__)) this_dir)
require File.expand_path('../../../fixtures/colocation_constraint', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/colocation_constraint', this_dir)
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) require File.expand_path('../../../helpers/cib_object', this_dir)
describe Pacemaker::Constraint::Colocation do describe Pacemaker::Constraint::Colocation do
let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup } let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup }

View File

@@ -1,8 +1,10 @@
require 'spec_helper' require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../../libraries/pacemaker/constraint/location', require File.expand_path('../../../../libraries/pacemaker/constraint/location',
File.dirname(__FILE__)) this_dir)
require File.expand_path('../../../fixtures/location_constraint', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/location_constraint', this_dir)
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) require File.expand_path('../../../helpers/cib_object', this_dir)
describe Pacemaker::Constraint::Location do describe Pacemaker::Constraint::Location do
let(:fixture) { Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup } let(:fixture) { Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup }

View File

@@ -1,10 +1,10 @@
require 'spec_helper' require 'spec_helper'
require File.expand_path('../../../../libraries/pacemaker/resource/clone',
File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../../../fixtures/clone_resource', File.dirname(__FILE__)) require File.expand_path('../../../../libraries/pacemaker/resource/clone', this_dir)
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/clone_resource', this_dir)
require File.expand_path('../../../helpers/meta_examples', require File.expand_path('../../../helpers/cib_object', this_dir)
File.dirname(__FILE__)) require File.expand_path('../../../helpers/meta_examples', this_dir)
describe Pacemaker::Resource::Clone do describe Pacemaker::Resource::Clone do
let(:fixture) { Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup } let(:fixture) { Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup }

View File

@@ -1,4 +1,5 @@
require 'spec_helper' require 'spec_helper'
require File.expand_path('../../../../libraries/pacemaker/resource/group', require File.expand_path('../../../../libraries/pacemaker/resource/group',
File.dirname(__FILE__)) File.dirname(__FILE__))
require File.expand_path('../../../fixtures/resource_group', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/resource_group', File.dirname(__FILE__))

View File

@@ -1,10 +1,10 @@
require 'spec_helper' require 'spec_helper'
require File.expand_path('../../../../libraries/pacemaker/resource/ms',
File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../../../fixtures/ms_resource', File.dirname(__FILE__)) require File.expand_path('../../../../libraries/pacemaker/resource/ms', this_dir)
require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/ms_resource', this_dir)
require File.expand_path('../../../helpers/meta_examples', require File.expand_path('../../../helpers/cib_object', this_dir)
File.dirname(__FILE__)) require File.expand_path('../../../helpers/meta_examples', this_dir)
describe Pacemaker::Resource::MasterSlave do describe Pacemaker::Resource::MasterSlave do
let(:fixture) { Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup } let(:fixture) { Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup }

View File

@@ -1,12 +1,11 @@
require 'spec_helper' require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../../libraries/pacemaker/resource/primitive', require File.expand_path('../../../../libraries/pacemaker/resource/primitive',
File.dirname(__FILE__)) this_dir)
require File.expand_path('../../../fixtures/keystone_primitive', require File.expand_path('../../../fixtures/keystone_primitive', this_dir)
File.dirname(__FILE__)) require File.expand_path('../../../helpers/cib_object', this_dir)
require File.expand_path('../../../helpers/cib_object', require File.expand_path('../../../helpers/meta_examples', this_dir)
File.dirname(__FILE__))
require File.expand_path('../../../helpers/meta_examples',
File.dirname(__FILE__))
describe Pacemaker::Resource::Primitive do describe Pacemaker::Resource::Primitive do
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup } let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }

View File

@@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
require File.expand_path('../../../libraries/pacemaker/resource',
File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../../fixtures/keystone_primitive', require File.expand_path('../../../libraries/pacemaker/resource', this_dir)
File.dirname(__FILE__)) require File.expand_path('../../fixtures/keystone_primitive', this_dir)
describe Pacemaker::Resource do describe Pacemaker::Resource do
describe "#running?" do describe "#running?" do

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
require File.expand_path('../fixtures/clone_resource', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/runnable_resource', this_dir)
require File.expand_path('../fixtures/clone_resource', this_dir)
describe "Chef::Provider::PacemakerClone" do describe "Chef::Provider::PacemakerClone" do
# for use inside examples: # for use inside examples:

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/provider', File.dirname(__FILE__))
require File.expand_path('../fixtures/colocation_constraint', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../fixtures/colocation_constraint', this_dir)
describe "Chef::Provider::PacemakerColocation" do describe "Chef::Provider::PacemakerColocation" do
# for use inside examples: # for use inside examples:

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
require File.expand_path('../fixtures/resource_group', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/runnable_resource', this_dir)
require File.expand_path('../fixtures/resource_group', this_dir)
describe "Chef::Provider::PacemakerGroup" do describe "Chef::Provider::PacemakerGroup" do
# for use inside examples: # for use inside examples:

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/provider', File.dirname(__FILE__))
require File.expand_path('../fixtures/location_constraint', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/provider', this_dir)
require File.expand_path('../fixtures/location_constraint', this_dir)
describe "Chef::Provider::PacemakerLocation" do describe "Chef::Provider::PacemakerLocation" do
# for use inside examples: # for use inside examples:

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
require File.expand_path('../fixtures/ms_resource', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/runnable_resource', this_dir)
require File.expand_path('../fixtures/ms_resource', this_dir)
describe "Chef::Provider::PacemakerMs" do describe "Chef::Provider::PacemakerMs" do
# for use inside examples: # for use inside examples:

View File

@@ -1,6 +1,8 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__)) require 'spec_helper'
require File.expand_path('../helpers/runnable_resource', File.dirname(__FILE__))
require File.expand_path('../fixtures/keystone_primitive', File.dirname(__FILE__)) this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/runnable_resource', this_dir)
require File.expand_path('../fixtures/keystone_primitive', this_dir)
describe "Chef::Provider::PacemakerPrimitive" do describe "Chef::Provider::PacemakerPrimitive" do
# for use inside examples: # for use inside examples: