lib/gh.rb in gh-0.0.1 vs lib/gh.rb in gh-0.1.0
- old
+ new
@@ -3,29 +3,37 @@
require 'forwardable'
module GH
autoload :Cache, 'gh/cache'
autoload :Case, 'gh/case'
+ autoload :LazyLoader, 'gh/lazy_loader'
autoload :Normalizer, 'gh/normalizer'
autoload :Remote, 'gh/remote'
autoload :Response, 'gh/response'
autoload :Stack, 'gh/stack'
autoload :Wrapper, 'gh/wrapper'
- def self.[](key)
- backend = Thread.current[:GH] ||= DefaultStack.build
- backend[key]
- end
-
def self.with(backend)
backend = DefaultStack.build(backend) if Hash === backend
- was, Thread.current[:GH] = Thread.current[:GH], backend
+ was, self.current = current, backend
yield
ensure
- Thread.current[:GH] = was
+ self.current = was
end
+ def self.current
+ Thread.current[:GH] ||= DefaultStack.new
+ end
+
+ def self.current=(backend)
+ Thread.current[:GH] = backend
+ end
+
+ extend SingleForwardable
+ def_delegators :current, :api_host, :[], :reset
+
DefaultStack = Stack.new do
+ use LazyLoader
use Cache
use Normalizer
use Remote
end
end