Sha256: d4298590dda8c86cb5fdf24910d536284655c50506af5141d628c69ef8cbf9c7

Contents?: true

Size: 1.48 KB

Versions: 25

Compression:

Stored size: 1.48 KB

Contents

require 'logger'
require 'percy/client'

module Percy
  def self.config
    @config ||= Percy::Config.new
  end

  def self.reset
    @config = nil
    @client = nil
    @logger = nil
  end

  # API client based on configured options.
  #
  # @return [Percy::Client] API client.
  def self.client(options = {})
    if !defined?(@client) || !@client
      @client = Percy::Client.new(
        config: config,
        client_info: options[:client_info],
        environment_info: options[:environment_info],
      )
    end

    @client
  end

  # @private
  def self.logger
    @logger if defined?(@logger)
    @logger ||= Logger.new(STDOUT)
    @logger.level = config.debug ? Logger::DEBUG : Logger::INFO
    @logger.formatter = proc do |severity, _datetime, _progname, msg|
      "[percy][#{severity}] #{msg}\n"
    end
    @logger
  end

  # @private
  if RUBY_VERSION >= '1.9'
    def self.respond_to_missing?(method_name, include_private = false)
      client.respond_to?(method_name, include_private)
    end
  end

  # @private
  if RUBY_VERSION < '1.9'
    def self.respond_to?(method_name, include_private = false)
      client.respond_to?(method_name, include_private) || super
    end
  end

  # @private
  def self.method_missing(method_name, *args, &block)
    return super unless client.respond_to?(method_name)
    client.send(method_name, *args, &block)
  end
  private :method_missing

  # @private
  def self.respond_to_missing?(method_name, _ = false)
    client.respond_to?(method_name)
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
percy-client-2.1.1 lib/percy.rb
percy-client-2.1.0 lib/percy.rb
percy-client-2.0.9 lib/percy.rb
percy-client-2.0.8 lib/percy.rb
percy-client-2.0.7 lib/percy.rb
percy-client-2.0.6 lib/percy.rb
percy-client-2.0.5 lib/percy.rb
percy-client-2.0.4 lib/percy.rb
percy-client-2.0.3 lib/percy.rb
percy-client-2.0.2 lib/percy.rb
percy-client-2.0.1 lib/percy.rb
percy-client-2.0.0 lib/percy.rb
percy-client-1.15.0 lib/percy.rb
percy-client-1.14.1 lib/percy.rb
percy-client-1.14.0 lib/percy.rb
percy-client-1.13.10 lib/percy.rb
percy-client-1.13.9 lib/percy.rb
percy-client-1.13.8 lib/percy.rb
percy-client-1.13.7 lib/percy.rb
percy-client-1.13.6 lib/percy.rb