appengine-rack 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ EOF
10
10
 
11
11
  spec = Gem::Specification.new do |s|
12
12
  s.name = "appengine-rack"
13
- s.version = "0.0.4"
13
+ s.version = "0.0.5"
14
14
  s.author = "Ryan Brown"
15
15
  s.email = "ribrdb@google.com"
16
16
  s.homepage = "http://code.google.com/p/appengine-jruby"
@@ -20,6 +20,7 @@ spec = Gem::Specification.new do |s|
20
20
 
21
21
  s.require_path = 'lib'
22
22
  s.files = %w(LICENSE Rakefile) + Dir.glob("lib/**/*")
23
+ s.add_dependency('rack')
23
24
  end
24
25
 
25
26
  task :default => :spec
@@ -15,10 +15,7 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- begin
19
- require 'bundler_gems/environment'
20
- rescue LoadError
21
- end
18
+ require 'rack'
22
19
 
23
20
  begin
24
21
  require 'appengine-apis/urlfetch'
@@ -26,15 +23,28 @@ begin
26
23
  rescue Exception
27
24
  end
28
25
 
26
+ class ::Rack::Builder
27
+
28
+ def skip_rack_servlet
29
+ @skip_defaults = true
30
+ end
31
+
32
+ def mime_mapping(mapping)
33
+ @mime_mapping = mapping
34
+ end
35
+
36
+ end
37
+
29
38
  module AppEngine
30
39
  module Rack
31
40
  ROOT = File.expand_path(File.dirname(__FILE__))
32
41
 
33
42
  class Resources
34
43
  COMMON_EXCLUDES = {
35
- :rails_excludes => %w(README Rakefile db/** doc/**
44
+ :rails_excludes => %w(README Rakefile db/** doc/** bin/**
36
45
  log/** script/** test/** tmp/**),
37
- :merb_excludes => %w(Rakefile autotest/** doc/** gems/** spec/**) }
46
+ :merb_excludes => %w(Rakefile autotest/** doc/** bin/**
47
+ gems/** spec/**) }
38
48
 
39
49
  def initialize
40
50
  @includes = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appengine-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brown
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 -08:00
12
+ date: 2009-12-03 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: |
17
26
  Commom dependencies for configuring an App Engine application via Rack.
18
27
 
@@ -27,7 +36,6 @@ files:
27
36
  - LICENSE
28
37
  - Rakefile
29
38
  - lib/appengine-rack.rb
30
- - lib/appengine-rack.rb.orig
31
39
  - lib/appengine-rack/java.rb
32
40
  has_rdoc: true
33
41
  homepage: http://code.google.com/p/appengine-jruby
@@ -1,259 +0,0 @@
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
- begin
19
- require 'bundler_gems/environment'
20
- rescue LoadError
21
- end
22
-
23
- begin
24
- require 'appengine-apis/urlfetch'
25
- require 'appengine-apis/tempfile'
26
- rescue Exception
27
- end
28
-
29
- module AppEngine
30
- module Rack
31
- ROOT = File.expand_path(File.dirname(__FILE__))
32
-
33
- class Resources
34
- COMMON_EXCLUDES = {
35
- :rails_excludes => %w(README Rakefile db/** doc/**
36
- log/** script/** test/** tmp/**),
37
- :merb_excludes => %w(Rakefile autotest/** doc/** gems/** spec/**) }
38
-
39
- def initialize
40
- @includes = []
41
- @excludes = []
42
- end
43
-
44
- def include(glob, expiration=nil)
45
- if glob.is_a? Array
46
- glob.each do |g|
47
- @includes << [g, expiration]
48
- end
49
- else
50
- @includes << [glob, expiration]
51
- end
52
- end
53
-
54
- def exclude(glob)
55
- if glob.is_a? Array
56
- @excludes += glob
57
- elsif glob.is_a? Symbol
58
- @excludes += COMMON_EXCLUDES[glob]
59
- else
60
- @excludes << glob
61
- end
62
- end
63
-
64
- def append_to(xml, type)
65
- resources = xml.add_element(type)
66
- @includes.each do |path, expiration|
67
- element = resources.add_element('include')
68
- element.add_attribute('path', path)
69
- element.add_attribute('expiration', expiration) if expiration
70
- end
71
- @excludes.each do |path|
72
- resources.add_element('exclude').add_attribute('path', path)
73
- end
74
- end
75
- end
76
-
77
- class PropertyMap < Hash
78
- def append_to(xml)
79
- unless empty?
80
- sys = xml.add_element('system-properties')
81
- each do |name, value|
82
- sys.add_element('property').
83
- add_attributes( { "name" => name, "value" => value.to_s } )
84
- end
85
- end
86
- end
87
- end
88
-
89
- class EnvVarMap < Hash
90
- def append_to(xml)
91
- unless empty?
92
- env = xml.add_element('env-variables')
93
- each do |name, value|
94
- env.add_element('env-var').
95
- add_attributes( { "name" => name, "value" => value.to_s } )
96
- end
97
- end
98
- end
99
- end
100
-
101
- class RackApplication
102
- attr_accessor :application, :precompilation_enabled
103
- attr_accessor :inbound_services, :mime_mapping
104
- attr_reader :version, :static_files, :resource_files, :public_root
105
- attr_reader :system_properties, :environment_variables
106
- attr_writer :ssl_enabled, :sessions_enabled
107
-
108
- def initialize
109
- @version = '1'
110
- @system_properties = PropertyMap[ 'os.arch' => '',
111
- 'jruby.jit.threshold' => 99,
112
- 'jruby.native.enabled' => false,
113
- 'jruby.management.enabled' => false,
114
- 'jruby.rack.input.rewindable' => false ]
115
- @environment_variables = EnvVarMap.new
116
- @static_files = Resources.new
117
- @resource_files = Resources.new
118
- @public_root = '/public'
119
- @inbound_services = []
120
- @mime_mapping = {}
121
- end
122
-
123
- alias id application
124
-
125
- def sessions_enabled?
126
- @sessions_enabled
127
- end
128
-
129
- def ssl_enabled?
130
- @ssl_enabled
131
- end
132
-
133
- def precompilation_enabled?
134
- @precompilation_enabled
135
- end
136
-
137
- def public_root=(root)
138
- root = "/#{root}".squeeze '/'
139
- root = nil if root.eql? '/'
140
- @public_root = root
141
- end
142
-
143
- def version=(version)
144
- @version = version.to_s
145
- end
146
-
147
- def configure(options={})
148
- [:system_properties, :environment_variables].each do |key|
149
- self.send(key).merge!(options.delete(key)) if options[key]
150
- end
151
- options.each { |k,v| self.send("#{k}=", v) }
152
- end
153
-
154
- def to_xml
155
- require 'rexml/document'
156
-
157
- xml = REXML::Document.new.add_element('appengine-web-app')
158
- xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0')
159
- xml.add_element('application').add_text(application)
160
- xml.add_element('version').add_text(version)
161
- xml.add_element('public-root').add_text(@public_root) if @public_root
162
- static_files.append_to(xml, 'static-files')
163
- resource_files.append_to(xml, 'resource-files')
164
- system_properties.append_to(xml)
165
- environment_variables.append_to(xml)
166
- if sessions_enabled?
167
- xml.add_element('sessions-enabled').add_text('true')
168
- end
169
- if ssl_enabled?
170
- xml.add_element('ssl-enabled').add_text('true')
171
- end
172
- if precompilation_enabled?
173
- xml.add_element('precompilation-enabled').add_text('true')
174
- end
175
- unless @inbound_services.empty?
176
- services = xml.add_element('inbound-services')
177
- @inbound_services.each do |service|
178
- services.add_element('service').add_text(service.to_s)
179
- end
180
- end
181
- @mime_mapping.each_pair do |key,val|
182
- mime = xml.add_element('mime-mapping')
183
- mime.add_element('extension').add_text(key.to_s)
184
- mime.add_element('mime-type').add_text(val)
185
- end
186
- return xml
187
- end
188
- end
189
-
190
- class SecurityMiddleware
191
- def self.append_xml(doc, pattern)
192
- security = doc.add_element('security-constraint')
193
- collection = security.add_element('web-resource-collection')
194
- collection.add_element('url-pattern').add_text(pattern)
195
- collection.add_element('url-pattern').add_text(
196
- AppEngine::Rack.make_wildcard(pattern))
197
- yield security
198
- end
199
-
200
- def self.new(app, *args, &block)
201
- app
202
- end
203
-
204
- end
205
-
206
- class AdminRequired < SecurityMiddleware
207
- def self.append_xml(doc, pattern)
208
- super(doc, pattern) do |security|
209
- auth = security.add_element('auth-constraint')
210
- auth.add_element('role-name').add_text('admin')
211
- end
212
- end
213
- end
214
-
215
- class LoginRequired < SecurityMiddleware
216
- def self.append_xml(doc, pattern)
217
- super(doc, pattern) do |security|
218
- auth = security.add_element('auth-constraint')
219
- auth.add_element('role-name').add_text('*')
220
- end
221
- end
222
- end
223
-
224
- class SSLRequired < SecurityMiddleware
225
- def self.append_xml(doc, pattern)
226
- super(doc, pattern) do |security|
227
- udc = security.add_element('user-data-constraint')
228
- udc.add_element('transport-guarantee').add_text('CONFIDENTIAL')
229
- end
230
- end
231
- end
232
-
233
- class << self
234
- def app
235
- @app ||= RackApplication.new
236
- end
237
-
238
- def configure_app(options={})
239
- @app = RackApplication.new
240
- @app.configure(options)
241
- end
242
-
243
- def environment
244
- if $servlet_context
245
- if $servlet_context.server_info =~ %r{^Google App Engine Development/}
246
- "development"
247
- elsif $servlet_context.server_info =~ %r{^Google App Engine/}
248
- "production"
249
- end
250
- end
251
- end
252
-
253
-
254
- def make_wildcard(pattern)
255
- "#{pattern}/*".squeeze('/')
256
- end
257
- end
258
- end
259
- end