Sha256: 5e17dc9f8ee954439bf0e557f8f3692b38caf74e56d94842b379ee72f846860f

Contents?: true

Size: 1.58 KB

Versions: 17

Compression:

Stored size: 1.58 KB

Contents

require_relative 'escape_sequence'
require_relative 'file'
require_relative 'html'
require_relative 'json'
require_relative 'null'
require_relative 'terminal'
require_relative 'text'

module Vedeu

  # Provides a single interface to all registered renderers.
  #
  # @api private
  module Renderers

    extend Enumerable
    extend self

    # Provides access to the list of renderers.
    #
    # @example
    #   Vedeu.renderers
    #
    # @api public
    # @return [Module]
    def renderers
      self
    end

    # @example
    #   Vedeu.renderers.render(*args)
    #
    # @return [Array<void>]
    def render(*args)
      threads = storage.map do |renderer|
        Thread.new(renderer) do
          mutex.synchronize do
            Vedeu.log(type: :debug, message: "Rendering with: '#{renderer}'")
            renderer.render(*args)
          end
        end
      end
      threads.each(&:join)
    end

    # Adds the given renderer class(es) to the list of renderers.
    #
    # @example
    #   Vedeu.renderer SomeRenderer
    #
    # @note
    #   A renderer class must respond to the '.render' class method.
    #
    # @param renderers [Class]
    # @return [Set]
    def renderer(*renderers)
      renderers.each { |renderer| storage.add(renderer) unless renderer.nil? }

      storage
    end

    # @example
    #   Vedeu.renderers.reset
    #
    # @return [Set]
    def reset
      @storage = Set.new
    end

    # @return [Set]
    def storage
      @storage ||= reset
    end

    private

    # @return [Mutex]
    def mutex
      @mutex ||= Mutex.new
    end

  end # Renderers

end # Vedeu

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
vedeu-0.4.50 lib/vedeu/output/renderers/all.rb
vedeu-0.4.49 lib/vedeu/output/renderers/all.rb
vedeu-0.4.48 lib/vedeu/output/renderers/all.rb
vedeu-0.4.47 lib/vedeu/output/renderers/all.rb
vedeu-0.4.46 lib/vedeu/output/renderers/all.rb
vedeu-0.4.45 lib/vedeu/output/renderers/all.rb
vedeu-0.4.44 lib/vedeu/output/renderers/all.rb
vedeu-0.4.43 lib/vedeu/output/renderers/all.rb
vedeu-0.4.42 lib/vedeu/output/renderers/all.rb
vedeu-0.4.41 lib/vedeu/output/renderers/all.rb
vedeu-0.4.40 lib/vedeu/output/renderers/all.rb
vedeu-0.4.39 lib/vedeu/output/renderers/all.rb
vedeu-0.4.38 lib/vedeu/output/renderers/all.rb
vedeu-0.4.37 lib/vedeu/output/renderers/all.rb
vedeu-0.4.36 lib/vedeu/output/renderers/all.rb
vedeu-0.4.35 lib/vedeu/output/renderers/all.rb
vedeu-0.4.34 lib/vedeu/output/renderers/all.rb