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

Side by Side 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 unified diff | Download patch
Property Changes:
Name: svn:executable
+ *
OLDNEW
(Empty)
1 #!/usr/bin/ruby1.8 -w
2 #
3 # Copyright:: Copyright 2009 Google Inc.
4 # Original Author:: Ryan Brown (mailto:ribrdb@google.com)
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 require 'rexml/document'
19 require 'rexml/formatters/pretty'
woodie 2009/07/03 00:59:21 not used here anymore
20
21 module AppEngine
22 module Rack
23 class Resources
24 def initialize
25 @includes = []
26 @excludes = []
27 end
28
29 def include(glob)
30 @includes << glob
31 end
32
33 def exclude(glob)
34 @excludes << glob
35 end
36
37 def to_xml(xml, type)
38 resources = REXML::Element.new(type)
39 @includes.each do |path|
40 resources.add_element('include').add_attribute('path', path)
41 end
42 @excludes.each do |path|
43 resources.add_element('exclude').add_attribute('path', path)
44 end
45 xml.add_element(resources)
46 end
47 end
48
49 class PropertyMap < Hash
50 def to_xml(xml)
51 unless empty?
52 sys = REXML::Element.new('system-properties')
53 each do |name, value|
54 sys.add_element('property').
55 add_attributes( { "name" => name, "value" => value } )
56 end
57 xml.add_element(sys)
58 end
59 end
60 end
61
62 class EnvVarMap < Hash
63 def to_xml(xml)
64 unless empty?
65 env = REXML::Element.new('env-variables')
66 each do |name, value|
67 env.add_element('env-var').
68 add_attributes( { "name" => name, "value" => value } )
69 end
70 xml.add_element(env)
71 end
72 end
73 end
74
75 class RackApplication
woodie 2009/07/03 02:39:57 # I liked my force-to-string mod, but with your wa
76 attr_accessor :application, :version
77 attr_writer :ssl_enabled, :sessions_enabled
78 attr_reader :system_properties, :environment_variables
79 attr_reader :static_files, :resource_files
80
81 def initialize
82 @version = '1'
83 @system_properties = PropertyMap[ 'os.arch' => '',
84 'jruby.management.enabled' => 'false' ]
85 @environment_variables = EnvVarMap.new
86 @static_files = Resources.new
87 @resource_files = Resources.new
88 end
89
90 def sessions_enabled?
91 @sessions_enabled
92 end
93
94 def ssl_enabled?
95 @ssl_enabled
96 end
97
98 def version=(version)
99 @version = version.to_s
100 end
101
102 def configure(options={})
103 [:system_properties, :environment_variables].each do |key|
104 self.send(key).merge!(options.delete(key)) if options[key]
105 end
106 options.each { |k,v| self.send("#{k}=", v) }
107 end
108
109 def to_xml
woodie 2009/07/03 00:59:21 It may be more appropriate to use doc doc = REXML
110 xml = REXML::Document.new.add_element('appengine-web-app')
111 xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0')
112 xml.add_element('application').add_text(application)
113 xml.add_element('version').add_text(version)
114 xml.add_element('public-root').add_text('/public')
115 static_files.to_xml(xml, 'static-files')
116 resource_files.to_xml(xml, 'resource-files')
117 system_properties.to_xml(xml)
118 environment_variables.to_xml(xml)
119 if sessions_enabled?
120 xml.add_element('sessions-enabled').add_text('true')
121 end
122 if ssl_enabled?
123 xml.add_element('ssl-enabled').add_text('true')
124 end
125 return xml
126 end
127 end
128
129 class << self
130 def app
131 @app ||= RackApplication.new
132 end
133
134 def configure(options={})
135 self.app.configure(options)
136 end
137
138 def environment
139 if $servlet_context
140 if $servlet_context.server_info =~ %r{^Google App Engine Development/}
141 "development"
142 elsif $servlet_context.server_info =~ %r{^Google App Engine/}
143 "production"
144 end
145 end
146 end
147 end
148 end
149 end
150
OLDNEW

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