Sha256: 18d6e07567948033519ab2f4d9275216bb1f80ae2914055d8301073d14a2f81e

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

require 'useless/doc/client'

module Useless
  module Doc
    class Proxy

      # +Doc::Proxy::Subject+ retrieves a +Doc::Core+ entity based upon
      # 'useless.doc.url', from a environment-appropriate +Doc::Client+,
      # and sets it to 'useless.doc.subject'.
      #
      class Subject
        def initialize(app)
          @app = app
        end

        def call(env)
          client = case ENV['RACK_ENV']
            when 'production'; Useless::Doc::Client.standard
            else               Useless::Doc::Client.stub
          end

          if env['useless.doc.logger']
            env['useless.doc.logger'].debug "selected Client: #{client.inspect}"
          end

          if env['useless.doc.subject'] = client.get(env['useless.doc.url'])
            if env['useless.doc.logger']
              env['useless.doc.logger'].info "retrieved subject for #{env['useless.doc.url']}"
              env['useless.doc.logger'].debug "retrieved subject: #{env['useless.doc.subject'].inspect}"
            end

            @app.call(env)
          else
            [404, {'Content-Type' => 'text/plain'}, ['Could not retrieve documentation.']]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
useless-doc-0.7.0 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.5 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.4 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.3 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.2 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.1 lib/useless/doc/proxy/subject.rb
useless-doc-0.6.0 lib/useless/doc/proxy/subject.rb
useless-doc-0.5.0 lib/useless/doc/proxy/subject.rb