Sha256: 4c2e07b7ee3e0a786cc15185b5fc5f4359a326ac20deab7f9e9e66871c809664

Contents?: true

Size: 705 Bytes

Versions: 1

Compression:

Stored size: 705 Bytes

Contents

module Rack
  module Logs
    class Viewer

      def initialize config
        @config = config
      end
      attr_reader :config

      def call env
        [200, headers, [joined_logs]]
      end

    private

      def headers
        {
          'Content-Type' => 'text/plain'
        }
      end

      def joined_logs
        logs.inject("") do |string, (filename, contents)|
          string + "## " + filename + "\n\n" + contents
        end
      end

      def logs
        files.inject({}) do |hash, filename|
          hash[filename] = ::File.read(filename)
          hash
        end
      end

      def files
        Dir[@config.log_dir+'/'+@config.pattern]
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-logs-0.0.1 lib/rack/logs/viewer.rb