Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(143)

Unified Diff: lib/appengine-tools/rack.rb

Issue 89083: Start the appengine-tools gem (Closed) SVN Base: http://appengine-jruby.googlecode.com/svn/trunk/appengine-tools/
Patch Set: Clean up xml formatting. Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: lib/appengine-tools/rack.rb
===================================================================
--- lib/appengine-tools/rack.rb (revision 0)
+++ lib/appengine-tools/rack.rb (revision 0)
@@ -0,0 +1,150 @@
+#!/usr/bin/ruby1.8 -w
+#
+# Copyright:: Copyright 2009 Google Inc.
+# Original Author:: Ryan Brown (mailto:ribrdb@google.com)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'rexml/document'
+require 'rexml/formatters/pretty'
woodie 2009/07/03 00:59:21 not used here anymore
+
+module AppEngine
+ module Rack
+ class Resources
+ def initialize
+ @includes = []
+ @excludes = []
+ end
+
+ def include(glob)
+ @includes << glob
+ end
+
+ def exclude(glob)
+ @excludes << glob
+ end
+
+ def to_xml(xml, type)
+ resources = REXML::Element.new(type)
+ @includes.each do |path|
+ resources.add_element('include').add_attribute('path', path)
+ end
+ @excludes.each do |path|
+ resources.add_element('exclude').add_attribute('path', path)
+ end
+ xml.add_element(resources)
+ end
+ end
+
+ class PropertyMap < Hash
+ def to_xml(xml)
+ unless empty?
+ sys = REXML::Element.new('system-properties')
+ each do |name, value|
+ sys.add_element('property').
+ add_attributes( { "name" => name, "value" => value } )
+ end
+ xml.add_element(sys)
+ end
+ end
+ end
+
+ class EnvVarMap < Hash
+ def to_xml(xml)
+ unless empty?
+ env = REXML::Element.new('env-variables')
+ each do |name, value|
+ env.add_element('env-var').
+ add_attributes( { "name" => name, "value" => value } )
+ end
+ xml.add_element(env)
+ end
+ end
+ end
+
+ class RackApplication
woodie 2009/07/03 02:39:57 # I liked my force-to-string mod, but with your wa
+ attr_accessor :application, :version
+ attr_writer :ssl_enabled, :sessions_enabled
+ attr_reader :system_properties, :environment_variables
+ attr_reader :static_files, :resource_files
+
+ def initialize
+ @version = '1'
+ @system_properties = PropertyMap[ 'os.arch' => '',
+ 'jruby.management.enabled' => 'false' ]
+ @environment_variables = EnvVarMap.new
+ @static_files = Resources.new
+ @resource_files = Resources.new
+ end
+
+ def sessions_enabled?
+ @sessions_enabled
+ end
+
+ def ssl_enabled?
+ @ssl_enabled
+ end
+
+ def version=(version)
+ @version = version.to_s
+ end
+
+ def configure(options={})
+ [:system_properties, :environment_variables].each do |key|
+ self.send(key).merge!(options.delete(key)) if options[key]
+ end
+ options.each { |k,v| self.send("#{k}=", v) }
+ end
+
+ def to_xml
woodie 2009/07/03 00:59:21 It may be more appropriate to use doc doc = REXML
+ xml = REXML::Document.new.add_element('appengine-web-app')
+ xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0')
+ xml.add_element('application').add_text(application)
+ xml.add_element('version').add_text(version)
+ xml.add_element('public-root').add_text('/public')
+ static_files.to_xml(xml, 'static-files')
+ resource_files.to_xml(xml, 'resource-files')
+ system_properties.to_xml(xml)
+ environment_variables.to_xml(xml)
+ if sessions_enabled?
+ xml.add_element('sessions-enabled').add_text('true')
+ end
+ if ssl_enabled?
+ xml.add_element('ssl-enabled').add_text('true')
+ end
+ return xml
+ end
+ end
+
+ class << self
+ def app
+ @app ||= RackApplication.new
+ end
+
+ def configure(options={})
+ self.app.configure(options)
+ end
+
+ def environment
+ if $servlet_context
+ if $servlet_context.server_info =~ %r{^Google App Engine Development/}
+ "development"
+ elsif $servlet_context.server_info =~ %r{^Google App Engine/}
+ "production"
+ end
+ end
+ end
+ end
+ end
+end
+
Property changes on: lib/appengine-tools/rack.rb
___________________________________________________________________
Name: svn:executable
+ *

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497