Sha256: 799488c626ae658c6188d26aeaf272db1840fffddd2637fa5f989482e4667711

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 KB

Contents

module Acfs

  # Global Acfs module methods.
  #
  module Global

    # @api private
    # @return [Runner]
    #
    def runner
      @runner ||= Runner.new Adapter::Typhoeus.new
    end

    # @api public
    #
    # Run all queued operations.
    #
    # @return [undefined]
    #
    def run
      runner.start
    end

    # @api public
    #
    # Configure acfs using given block.
    #
    # @return [undefined]
    # @see Configuration#configure
    #
    def configure(&block)
      Configuration.current.configure &block
    end

    # @api public
    #
    # Reset all queues, stubs and internal state.
    #
    def reset
      self.runner.clear
      Acfs::Stub.clear
    end

    # @api public
    #
    # Add an additional callback hook to not loaded resource.
    # If given resource already loaded callback will be invoked immediately.
    #
    # This method will be replaced by explicit callback handling when query methods
    # return explicit future objects.
    #
    # @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__)
      return false if block.nil?

      if resource.loaded?
        block.call resource
      else
        resource.__callbacks__ << block
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
acfs-0.34.1.1.b289 lib/acfs/global.rb
acfs-0.34.1 lib/acfs/global.rb
acfs-0.34.0.1.b288 lib/acfs/global.rb
acfs-0.34.0.1.b287 lib/acfs/global.rb
acfs-0.34.0.1.b286 lib/acfs/global.rb
acfs-0.34.0 lib/acfs/global.rb
acfs-0.33.1.1.b285 lib/acfs/global.rb
acfs-0.33.1.1.b281 lib/acfs/global.rb
acfs-0.33.1 lib/acfs/global.rb
acfs-0.33.0.1.b278 lib/acfs/global.rb
acfs-0.33.0 lib/acfs/global.rb
acfs-0.32.1.1.b277 lib/acfs/global.rb
acfs-0.32.1.1.b276 lib/acfs/global.rb
acfs-0.32.1.1.b275 lib/acfs/global.rb
acfs-0.32.1.1.b274 lib/acfs/global.rb
acfs-0.32.1.1.b272 lib/acfs/global.rb
acfs-0.32.1 lib/acfs/global.rb
acfs-0.32.0.1.b270 lib/acfs/global.rb
acfs-0.31.0.1.b269 lib/acfs/global.rb
acfs-0.32.0 lib/acfs/global.rb