Sha256: 96c0bcc8ad7ee96cf2e229a551437c5fca041e5ba0e3ec292085f24fe2225293

Contents?: true

Size: 1.94 KB

Versions: 26

Compression:

Stored size: 1.94 KB

Contents

module Skylight
  module Normalizers
    module ActionController

      # 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
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
skylight-0.8.0.beta.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.7.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.7.0.beta.3 lib/skylight/normalizers/action_controller/send_file.rb
truex-skylight-0.6.0 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.7.0.beta.2 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.7.0.beta.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.6.2.beta.2 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.6.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.6.0 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.6.0.beta.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.5.2 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.5.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.5.0 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.3 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.5.0.beta1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.2 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.1 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.0 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.0.beta2 lib/skylight/normalizers/action_controller/send_file.rb
skylight-0.4.0.beta1 lib/skylight/normalizers/action_controller/send_file.rb