Skip to content

Instantly share code, notes, and snippets.

@nickpoorman
Created April 10, 2012 16:05
Show Gist options
  • Save nickpoorman/2352433 to your computer and use it in GitHub Desktop.
Save nickpoorman/2352433 to your computer and use it in GitHub Desktop.
Deadlock Env
>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
> rails -v
Rails 3.2.3
GIT
  remote: git://github.com/plataformatec/simple_form.git
  revision: 51f680a9a2233748669655d81c82f96bef775298
  specs:
    simple_form (2.0.2.dev)
      actionpack (~> 3.0)
      activemodel (~> 3.0)

GIT
  remote: git://github.com/seyhunak/twitter-bootstrap-rails.git
  revision: 2b119e7a83f34202b6ea7f61cd3da59b170ebdd8
  branch: static
  specs:
    twitter-bootstrap-rails (2.0.1)
      actionpack
      railties

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (3.1.4)
      actionpack (= 3.1.4)
      mail (~> 2.3.0)
    actionpack (3.1.4)
      activemodel (= 3.1.4)
      activesupport (= 3.1.4)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      i18n (~> 0.6)
      rack (~> 1.3.6)
      rack-cache (~> 1.1)
      rack-mount (~> 0.8.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.0.3)
    activemodel (3.1.4)
      activesupport (= 3.1.4)
      builder (~> 3.0.0)
      i18n (~> 0.6)
    activerecord (3.1.4)
      activemodel (= 3.1.4)
      activesupport (= 3.1.4)
      arel (~> 2.2.3)
      tzinfo (~> 0.3.29)
    activeresource (3.1.4)
      activemodel (= 3.1.4)
      activesupport (= 3.1.4)
    activesupport (3.1.4)
      multi_json (~> 1.0)
    addressable (2.2.7)
    arel (2.2.3)
    awesome_print (1.0.2)
    bcrypt-ruby (3.0.1-x86-mingw32)
    bson (1.6.1)
    bson_ext (1.6.1)
      bson (~> 1.6.1)
    builder (3.0.0)
    capybara (1.1.2)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      selenium-webdriver (~> 2.0)
      xpath (~> 0.1.4)
    carrierwave (0.5.8)
      activesupport (~> 3.0)
    carrierwave-mongoid (0.1.6)
      carrierwave (~> 0.5.6)
      mongoid (~> 2.1)
    childprocess (0.3.1)
      ffi (~> 1.0.6)
    coffee-rails (3.1.1)
      coffee-script (>= 2.2.0)
      railties (~> 3.1.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.2.0)
    daemons (1.1.8)
    diff-lcs (1.1.3)
    erubis (2.7.0)
    eventmachine (1.0.0.beta.4.1-x86-mingw32)
    execjs (1.3.0)
      multi_json (~> 1.0)
    factory_girl (3.0.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (3.0.0)
      factory_girl (~> 3.0.0)
      railties (>= 3.0.0)
    faraday (0.7.6)
      addressable (~> 2.2)
      multipart-post (~> 1.1)
      rack (~> 1.1)
    ffi (1.0.11)
    frontend-helpers (0.1.2)
      haml-rails
      rails (~> 3.1.0)
      sass-rails
      sprockets
    guard (1.0.1)
      ffi (>= 0.5.0)
      thor (~> 0.14.6)
    guard-rspec (0.7.0)
      guard (>= 0.10.0)
    haml (3.1.4)
    haml-rails (0.3.4)
      actionpack (~> 3.0)
      activesupport (~> 3.0)
      haml (~> 3.0)
      railties (~> 3.0)
    heroku (2.23.0)
      launchy (>= 0.3.2)
      netrc (~> 0.7.1)
      rest-client (~> 1.6.1)
      rubyzip
    hike (1.2.1)
    i18n (0.6.0)
    jquery-rails (1.0.19)
      railties (~> 3.0)
      thor (~> 0.14)
    json (1.6.6)
    launchy (2.1.0)
      addressable (~> 2.2.6)
    libnotify (0.7.2)
      ffi (~> 1.0.0)
    mail (2.3.3)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.18)
    mongo (1.6.1)
      bson (~> 1.6.1)
    mongoid (2.4.7)
      activemodel (~> 3.1)
      mongo (~> 1.3)
      tzinfo (~> 0.3.22)
    multi_json (1.2.0)
    multipart-post (1.1.5)
    netrc (0.7.1)
    nokogiri (1.5.2-x86-mingw32)
    oauth (0.4.5)
    oauth2 (0.5.2)
      faraday (~> 0.7)
      multi_json (~> 1.0)
    polyglot (0.3.3)
    rack (1.3.6)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-mount (0.8.3)
      rack (>= 1.0.0)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.1)
      rack (>= 1.0)
    rails (3.1.4)
      actionmailer (= 3.1.4)
      actionpack (= 3.1.4)
      activerecord (= 3.1.4)
      activeresource (= 3.1.4)
      activesupport (= 3.1.4)
      bundler (~> 1.0)
      railties (= 3.1.4)
    railties (3.1.4)
      actionpack (= 3.1.4)
      activesupport (= 3.1.4)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (~> 0.14.6)
    rake (0.9.2.2)
    rb-fsevent (0.9.0)
    rb-inotify (0.8.8)
      ffi (>= 0.5.0)
    rdoc (3.12)
      json (~> 1.4)
    rest-client (1.6.7)
      mime-types (>= 1.16)
    rspec (2.9.0)
      rspec-core (~> 2.9.0)
      rspec-expectations (~> 2.9.0)
      rspec-mocks (~> 2.9.0)
    rspec-core (2.9.0)
    rspec-expectations (2.9.1)
      diff-lcs (~> 1.1.3)
    rspec-mocks (2.9.0)
    rspec-rails (2.9.0)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec (~> 2.9.0)
    rubyzip (0.9.6.1)
    sass (3.1.15)
    sass-rails (3.1.6)
      actionpack (~> 3.1.0)
      railties (~> 3.1.0)
      sass (>= 3.1.10)
      tilt (~> 1.3.2)
    selenium-webdriver (2.20.0)
      childprocess (>= 0.2.5)
      ffi (~> 1.0)
      multi_json (~> 1.0)
      rubyzip
    sorcery (0.7.7)
      bcrypt-ruby (~> 3.0.0)
      oauth (~> 0.4.4)
      oauth2 (~> 0.5.1)
      sorcery
    sprockets (2.0.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    thin (1.3.1)
      daemons (>= 1.0.9)
      eventmachine (>= 0.12.6)
      rack (>= 1.0.0)
    thor (0.14.6)
    tilt (1.3.3)
    treetop (1.4.10)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.32)
    uglifier (1.2.4)
      execjs (>= 0.3.0)
      multi_json (>= 1.0.2)
    xpath (0.1.4)
      nokogiri (~> 1.3)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  awesome_print
  bson_ext
  capybara
  carrierwave
  carrierwave-mongoid
  coffee-rails
  eventmachine (>= 1.0.0.beta)
  factory_girl_rails
  frontend-helpers
  guard-rspec
  heroku
  jquery-rails
  libnotify
  mongoid
  rack
  rails
  rb-fsevent
  rb-inotify
  rspec-rails
  sass-rails (~> 3.1.5)
  simple_form!
  sorcery
  thin
  twitter-bootstrap-rails!
  uglifier
class ServeGridfsAttachment
  def initialize(app)
    @app = app
  end

  def call(env)
    if env["PATH_INFO"] =~ /^\/grid\/(.+)$/
      process_request(env, $1)
    else
      @app.call(env)
    end
  end

  private  
  def process_request(env, key)
    begin
      Mongo::GridFileSystem.new(Mongoid.database).open(key, 'r') do |file|
        [200, { 'Content-Type' => file.content_type }, [file.read]]
      end
    rescue
      [404, { 'Content-Type' => 'text/plain' }, ['File not found.']]
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment