Skip to content

Instantly share code, notes, and snippets.

@wmw
Created November 9, 2010 20:53
Show Gist options
  • Select an option

  • Save wmw/669775 to your computer and use it in GitHub Desktop.

Select an option

Save wmw/669775 to your computer and use it in GitHub Desktop.

Revisions

  1. wmw created this gist Nov 9, 2010.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    require 'mm-paginate'

    if ENV['MONGOHQ_URL']
    MongoMapper.config = {RAILS_ENV => {'uri' => ENV['MONGOHQ_URL']}}
    else
    MongoMapper.config = {RAILS_ENV => {'uri' => 'mongodb://localhost:27071/shapado-development'}}
    end

    MongoMapperExt.init

    if defined?(PhusionPassenger)
    PhusionPassenger.on_event(:starting_worker_process) do |forked|
    MongoMapper.connection.connect_to_master if forked
    end
    end

    Dir.glob("#{RAILS_ROOT}/app/models/**/*.rb") do |model_path|
    File.basename(model_path, ".rb").classify.constantize
    end

    # HACK: do not create indexes on every request
    module MongoMapper::Plugins::Indexes::ClassMethods
    def ensure_index(*args)
    end
    end

    Dir.glob("#{RAILS_ROOT}/app/javascripts/**/*.js") do |js_path|
    code = File.read(js_path)
    name = File.basename(js_path, ".js")

    # HACK: looks like ruby driver doesn't support this
    MongoMapper.database.eval("db.system.js.save({_id: '#{name}', value: #{code}})")
    end

    require 'support/versionable'