Sha256: aeed92d1911236c7af57ef2dc0b671f7fedefc65308a93684bda52a7f37e4f82

Contents?: true

Size: 1.96 KB

Versions: 7

Compression:

Stored size: 1.96 KB

Contents

# explicit request types
module Wunderbar
  module Options
    XHR_JSON  = ARGV.delete('--json')
    TEXT      = ARGV.delete('--text')
  end

  @@unsafe = false

  def self.unsafe!(mode=true)
    @@unsafe=mode
  end

  def self.safe?
    if $SAFE == 0 and not @@unsafe
      # some gems (e.g. em-websocket-0.3.6) insert unsafe entries into the
      # path, and that prevents requires from succeeding.  If it looks like
      # we are about to make a transition to $SAFE=1, clean up that mess
      # before proceeding.
      #
      # the goal of $SAFE is not to protect us against software which was
      # installed by the owner of the site, but from injection attacks
      # contained within data provided by users of the site.
      $:.each_with_index do |path, index|
        if path.tainted?
          $:[index] = File.expand_path(path.dup.untaint).untaint
        end
      end
    end

    not @@unsafe
  end

  class Scope
    attr_accessor :env
    def initialize(env)
      @env = env
    end
  end

  @@templates = {}

  def self.templates
    @@templates
  end

  module API
    def _html(*args, &block)
      Wunderbar.html(*args, &block)
    end

    def _xhtml(*args, &block)
      Wunderbar.xhtml(*args, &block)
    end

    def _json(*args, &block)
      Wunderbar.json(*args, &block)
    end

    def _text(*args, &block)
      Wunderbar.text(*args, &block)
    end

    def _websocket(*args, &block)
      args.last[:sync]=args.last.fetch(:sync,true) if Hash === args.last
      Wunderbar.websocket(*args, &block)
    end

    def _template(name, &block)
      Wunderbar.templates[name.to_s.gsub('_','-')] = block
    end
  end
end

require 'socket'
$SERVER = ENV['HTTP_HOST'] || Socket::gethostname

# set encoding to UTF-8
ENV['LANG'] ||= "en_US.UTF-8"
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

# Add methods to the 'main' object
if self.to_s == 'main'
  class << self
    include Wunderbar::API

    def env
      ENV
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
wunderbar-0.24.0 lib/wunderbar/environment.rb
wunderbar-0.23.2 lib/wunderbar/environment.rb
wunderbar-0.23.1 lib/wunderbar/environment.rb
wunderbar-0.23.0 lib/wunderbar/environment.rb
wunderbar-0.22.4 lib/wunderbar/environment.rb
wunderbar-0.22.3 lib/wunderbar/environment.rb
wunderbar-0.22.2 lib/wunderbar/environment.rb