lib/acfs/global.rb in acfs-1.0.0.dev.1.b305 vs lib/acfs/global.rb in acfs-1.0.0

- old
+ new

@@ -1,16 +1,24 @@ module Acfs - + # # Global Acfs module methods. # module Global - + # # @api private # @return [Runner] # def runner - @runner ||= Runner.new Adapter::Typhoeus.new + Thread.current[:acfs_runner] ||= begin + adapter = Configuration.current.adapter + + if adapter + Runner.new adapter.call + else + Runner.new Adapter::Typhoeus.new + end + end end # @api public # # Run all queued operations. @@ -57,13 +65,14 @@ # @example # user = MyUser.find 1, &callback_one # Acfs.add_callback(user, &callback_two) # def add_callback(resource, &block) - raise ArgumentError.new "Given resource is not an Acfs resource but "\ - "a: #{resource.class.name}" \ - unless resource.respond_to?(:__callbacks__) + unless resource.respond_to?(:__callbacks__) + raise ArgumentError.new 'Given resource is not an Acfs resource ' \ + "delegator but a: #{resource.class.name}" + end return false if block.nil? if resource.loaded? block.call resource else @@ -71,10 +80,10 @@ end end def on(*resources) resources.each do |resource| - add_callback resource do |ret| + add_callback resource do |_| yield(*resources) unless resources.any? {|res| !res.loaded? } end end end end