Skip to content

Commit

Permalink
Change class var to class instance var
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Apr 13, 2016
1 parent 7e28cb3 commit c51411c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions lib/hanami/container.rb
Expand Up @@ -21,8 +21,8 @@ def hanami_app?(app)

def self.configure(options = {}, &blk)
Mutex.new.synchronize do
@@options = options
@@configuration = blk
@options = options
@configuration = blk
end
end

Expand All @@ -38,15 +38,16 @@ def call(env)
end

private

def assert_configuration_presence!
unless self.class.class_variable_defined?(:@@configuration)
unless self.class.instance_variable_defined?(:@configuration)
raise ArgumentError.new("#{ self.class } doesn't have any application mounted.")
end
end

def prepare_middleware_stack!
@builder = ::Rack::Builder.new
@routes = Router.new(&@@configuration)
@routes = Router.new(&self.class.instance_variable_get(:@configuration))

if Hanami.environment.serve_static_assets?
require 'hanami/static'
Expand Down
12 changes: 6 additions & 6 deletions test/commands/console_test.rb
Expand Up @@ -180,12 +180,12 @@ def load_engine(engine)
before do
@old_pwd = Dir.pwd
Dir.chdir 'test/fixtures/microservices'
Hanami::Container.class_variable_set(:@@configuration, Proc.new{})
Hanami::Container.instance_variable_set(:@configuration, Proc.new{})
end

after do
Dir.chdir @old_pwd
Hanami::Container.remove_class_variable(:@@configuration)
Hanami::Container.remove_instance_variable(:@configuration)
end

it 'requires that file and starts a console session' do
Expand Down Expand Up @@ -216,11 +216,11 @@ def load_engine(engine)
}

before do
Hanami::Container.class_variable_set(:@@configuration, Proc.new{})
Hanami::Container.instance_variable_set(:@configuration, Proc.new{})
end

after do
Hanami::Container.remove_class_variable(:@@configuration)
Hanami::Container.remove_instance_variable(:@configuration)
end

it 'requires that file and starts a console session' do
Expand Down Expand Up @@ -251,12 +251,12 @@ def load_engine(engine)

@engine = Minitest::Mock.new
@engine.expect(:start, nil)
Hanami::Container.class_variable_set(:@@configuration, Proc.new{})
Hanami::Container.instance_variable_set(:@configuration, Proc.new{})
end

after do
Hanami::Utils::IO.silence_warnings { TOPLEVEL_BINDING = @old_main }
Hanami::Container.remove_class_variable(:@@configuration)
Hanami::Container.remove_instance_variable(:@configuration)
end

it 'mixes convenience methods into the TOPLEVEL_BINDING' do
Expand Down
6 changes: 3 additions & 3 deletions test/container_test.rb
Expand Up @@ -9,14 +9,14 @@
end

it 'allows to define mounted applications with a block' do
assert Hanami::Container.class_variable_get(:@@configuration) == @blk, "Expected Hanami::Container configuration to equal @blk"
assert Hanami::Container.instance_variable_get(:@configuration) == @blk, "Expected Hanami::Container configuration to equal @blk"
end

it 'allows to redefine the configuration' do
blk = -> { mount RackApp, at: '/rack2' }
Hanami::Container.configure(&blk)

assert Hanami::Container.class_variable_get(:@@configuration) == blk, "Expected Hanami::Container configuration to equal blk"
assert Hanami::Container.instance_variable_get(:@configuration) == blk, "Expected Hanami::Container configuration to equal blk"
end
end

Expand All @@ -36,7 +36,7 @@

describe 'without configuration' do
before do
Hanami::Container.remove_class_variable(:@@configuration) rescue nil
Hanami::Container.remove_instance_variable(:@configuration) rescue nil
end

it 'raises error when initialized' do
Expand Down

0 comments on commit c51411c

Please sign in to comment.