Skip to content

Commit

Permalink
Stop installing the global configatron method when loading configatro…
Browse files Browse the repository at this point in the history
…n/core
  • Loading branch information
gdb committed Jun 7, 2014
1 parent 53ad13d commit 04741cf
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -20,6 +20,7 @@ GEM
mocha (1.0.0)
metaclass (~> 0.0.1)
rake (10.2.2)
subprocess (1.0.0)

PLATFORMS
ruby
Expand All @@ -30,3 +31,4 @@ DEPENDENCIES
minitest (>= 5.2.3)
mocha
rake
subprocess
1 change: 1 addition & 0 deletions configatron.gemspec
Expand Up @@ -20,5 +20,6 @@ Gem::Specification.new do |gem|

gem.add_development_dependency "rake"
gem.add_development_dependency "mocha"
gem.add_development_dependency "subprocess"
gem.add_development_dependency "minitest", '>=5.2.3'
end
10 changes: 9 additions & 1 deletion lib/configatron.rb
Expand Up @@ -3,7 +3,7 @@

require 'configatron/deep_clone'
require 'configatron/errors'
require 'configatron/kernel'
require 'configatron/kernel_store'
require 'configatron/store'

# Proc *must* load before dynamic/delayed, or else Configatron::Proc
Expand All @@ -14,3 +14,11 @@

class Configatron
end

# NO_EXT gets defined when you require "configatron/core", which
# signals that you don't want any extensions. It'd be nice to have a
# better internal signaling mechanism (could use environment
# variables, but then they become part of the public interface).
unless defined?(Configatron::NO_EXT)
require 'configatron/ext/kernel'
end
6 changes: 5 additions & 1 deletion lib/configatron/core.rb
@@ -1,2 +1,6 @@
$stderr.puts "Warning: Loading 'configatron/core' has been deprecated. Please just load 'configatron directly."
class Configatron
# Signals that we should not load the extensions.
NO_EXT = true
end

require 'configatron'
5 changes: 5 additions & 0 deletions lib/configatron/ext/kernel.rb
@@ -0,0 +1,5 @@
module Kernel
def configatron
Configatron::KernelStore.instance
end
end
6 changes: 0 additions & 6 deletions lib/configatron/kernel.rb → lib/configatron/kernel_store.rb
Expand Up @@ -50,9 +50,3 @@ def unlock!
@locked = false
end
end

module Kernel
def configatron
Configatron::KernelStore.instance
end
end
11 changes: 11 additions & 0 deletions test/functional/_lib/scripts/core.rb
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

if defined?(configatron)
raise "`configatron` method was defined at load-time!"
end

require 'configatron/core'

if defined?(configatron)
raise "Loaded configatron/core but `configatron` was defined!"
end
10 changes: 10 additions & 0 deletions test/functional/loading.rb
@@ -0,0 +1,10 @@
require_relative '_lib'
require 'subprocess'

class Critic::Functional::ConfigatronTest < Critic::Functional::Test
describe 'loading' do
it 'does not define top-level configatron method if loading configatron/core' do
Subprocess.check_call([File.expand_path('../_lib/scripts/core.rb', __FILE__)])
end
end
end
File renamed without changes.

0 comments on commit 04741cf

Please sign in to comment.