Sha256: 786355c4df05703f45859b4cf239e63823a82bef7f4af7f8b0b10d5feeb51fc1

Contents?: true

Size: 1.8 KB

Versions: 25

Compression:

Stored size: 1.8 KB

Contents

module Skylight
  module Normalizers

    # Temporary hacks
    begin
      require "action_dispatch/http/mime_type"
      require "action_dispatch/http/mime_types"
      require "rack/utils"

      class SendFile < Normalizer
        register "send_file.action_controller"

        CAT = "app.controller.send_file".freeze
        TITLE = "send file".freeze

        def normalize(trace, name, payload)
          path = payload[:path]

          annotations = {
            path:        path,
            filename:    payload[:filename],
            type:        normalize_type(payload),
            disposition: normalize_disposition(payload),
            status:      normalize_status(payload) }

          title = TITLE

          # depending on normalization, we probably want this to eventually
          # include the full path, but we need to make sure we have a good
          # deduping strategy first.
          desc = nil

          [ CAT, title, desc, annotations ]
        end

      private

        OCTET_STREAM = "application/octet-stream".freeze
        ATTACHMENT = "attachment".freeze

        def initialize(*)
          super

          @mimes = Mime::SET.reduce({}) do |hash, mime|
            hash[mime.symbol] = mime.to_s.dup.freeze
            hash
          end
        end

        def normalize_type(payload)
          type = payload[:type] || OCTET_STREAM
          type = @mimes[type] if type.is_a?(Symbol)
          type
        end

        def mime_for(type)
          @mimes[type] ||= Mime[type].to_s.freeze
        end

        def normalize_status(payload)
          status = payload[:status] || 200
          Rack::Utils.status_code(status)
        end

        def normalize_disposition(payload)
          payload[:disposition] || ATTACHMENT
        end
      end

    rescue LoadError
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
skylight-0.3.14 lib/skylight/normalizers/send_file.rb
skylight-0.3.13 lib/skylight/normalizers/send_file.rb
skylight-0.3.12 lib/skylight/normalizers/send_file.rb
skylight-0.3.11 lib/skylight/normalizers/send_file.rb
skylight-0.3.10 lib/skylight/normalizers/send_file.rb
skylight-0.3.8 lib/skylight/normalizers/send_file.rb
skylight-0.3.7 lib/skylight/normalizers/send_file.rb
skylight-0.3.6 lib/skylight/normalizers/send_file.rb
skylight-0.3.3 lib/skylight/normalizers/send_file.rb
skylight-0.3.2 lib/skylight/normalizers/send_file.rb
skylight-0.3.1 lib/skylight/normalizers/send_file.rb
skylight-0.3.0 lib/skylight/normalizers/send_file.rb
skylight-0.2.7 lib/skylight/normalizers/send_file.rb
skylight-0.2.6 lib/skylight/normalizers/send_file.rb
skylight-0.3.0.rc.6 lib/skylight/normalizers/send_file.rb
skylight-0.2.5 lib/skylight/normalizers/send_file.rb
skylight-0.2.4 lib/skylight/normalizers/send_file.rb
skylight-0.3.0.rc.5 lib/skylight/normalizers/send_file.rb
skylight-0.3.0.rc.4 lib/skylight/normalizers/send_file.rb
skylight-0.3.0.rc.3 lib/skylight/normalizers/send_file.rb