Sha256: dc7e349588bd08175921813335d2a4e9419436f99a10232027fbe9df6e2ae990

Contents?: true

Size: 684 Bytes

Versions: 8

Compression:

Stored size: 684 Bytes

Contents

module Lurker
  class Sandbox
    def initialize(app)
      @app = app
    end

    def call(env)
      orig_path = env['PATH_INFO']
      if orig_path.ends_with?('.js') || orig_path.ends_with?('css') || orig_path.ends_with?('css.map')
        @result = @app.call(env)
      else
        ActiveRecord::Base.transaction do
          @result = @app.call(env)
          raise ActiveRecord::Rollback if called_from_lurker?(env)
        end
      end
      @result
    end

    private

    def called_from_lurker?(env)
      return false if (referer = env['HTTP_REFERER']).blank?
      url = URI.parse referer
      url.path.starts_with? "/#{Lurker::DEFAULT_URL_BASE}"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lurker-0.6.1 lib/lurker/sandbox.rb
lurker-0.5.7 lib/lurker/sandbox.rb
lurker-0.6.0 lib/lurker/sandbox.rb
lurker-0.5.6 lib/lurker/sandbox.rb
lurker-0.5.5 lib/lurker/sandbox.rb
lurker-0.5.4 lib/lurker/sandbox.rb
lurker-0.5.3 lib/lurker/sandbox.rb
lurker-0.5.2 lib/lurker/sandbox.rb