appengine-apis 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +0 -1
- data/Rakefile +1 -2
- data/lib/appengine-apis/datastore.rb +9 -1
- data/lib/appengine-apis/datastore_types.rb +14 -8
- data/lib/appengine-apis/sdk.rb +15 -12
- data/lib/appengine-apis/testing.rb +7 -2
- data/lib/appengine-apis/users.rb +18 -4
- data/lib/appengine-apis.rb +1 -1
- data/spec/datastore_spec.rb +17 -0
- data/spec/datastore_types_spec.rb +8 -0
- data/spec/users_spec.rb +11 -0
- metadata +3 -5
- data/PostInstall.txt +0 -12
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
gem 'rdoc'
|
7
7
|
require 'sdoc'
|
8
8
|
ENV['RDOCOPT'] = '-T lightblue'
|
9
|
-
rescue
|
9
|
+
rescue Exception
|
10
10
|
end
|
11
11
|
|
12
12
|
# Generate all the Rake tasks
|
@@ -14,7 +14,6 @@ end
|
|
14
14
|
$hoe = Hoe.new('appengine-apis', AppEngine::VERSION) do |p|
|
15
15
|
p.developer('Ryan Brown', 'ribrdb@gmail.com')
|
16
16
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
17
|
-
p.post_install_message = 'PostInstall.txt'
|
18
17
|
p.rubyforge_name = 'appengine-jruby'
|
19
18
|
# p.extra_deps = [
|
20
19
|
# ['activesupport','>= 2.0.2'],
|
@@ -204,7 +204,7 @@ module Datastore
|
|
204
204
|
# aren't safe to occur multiple times. However, this doesn't
|
205
205
|
# include Put, Get, and Delete calls, of course.
|
206
206
|
#
|
207
|
-
def transaction(retries=
|
207
|
+
def transaction(retries=3)
|
208
208
|
while retries >= 0
|
209
209
|
retries -= 1
|
210
210
|
tx = begin_transaction
|
@@ -276,6 +276,12 @@ module Datastore
|
|
276
276
|
|
277
277
|
ASCENDING = JQuery::SortDirection::ASCENDING
|
278
278
|
DESCENDING = JQuery::SortDirection::DESCENDING
|
279
|
+
|
280
|
+
OP_MAP = Hash.new { |hash, key| key }
|
281
|
+
OP_MAP.update('==' => EQUAL, '>' => GREATER_THAN,
|
282
|
+
'>=' => GREATER_THAN_OR_EQUAL, '<' => LESS_THAN,
|
283
|
+
'<=' => LESS_THAN_OR_EQUAL)
|
284
|
+
OP_MAP.freeze
|
279
285
|
end
|
280
286
|
include Constants
|
281
287
|
|
@@ -353,6 +359,8 @@ module Datastore
|
|
353
359
|
#
|
354
360
|
def filter(name, operator, value)
|
355
361
|
name = name.to_s if name.kind_of? Symbol
|
362
|
+
operator = operator.to_s if operator.kind_of? Symbol
|
363
|
+
operator = OP_MAP[operator]
|
356
364
|
value = Datastore.ruby_to_java(value)
|
357
365
|
@query.add_filter(name, operator, value)
|
358
366
|
clear_cache
|
@@ -247,12 +247,7 @@ module AppEngine
|
|
247
247
|
def get_property(name)
|
248
248
|
name = name.to_s if name.kind_of? Symbol
|
249
249
|
prop = Datastore.convert_exceptions { getProperty(name) }
|
250
|
-
|
251
|
-
if ruby_type
|
252
|
-
ruby_type.new_from_java(prop)
|
253
|
-
else
|
254
|
-
prop
|
255
|
-
end
|
250
|
+
java_value_to_ruby(prop)
|
256
251
|
end
|
257
252
|
alias :[] :get_property
|
258
253
|
|
@@ -314,8 +309,10 @@ module AppEngine
|
|
314
309
|
alias merge! update
|
315
310
|
|
316
311
|
# Iterates over all the properties in this Entity.
|
317
|
-
def each(
|
318
|
-
getProperties.each
|
312
|
+
def each() # :yields: name, value
|
313
|
+
getProperties.each do |name, value|
|
314
|
+
yield name, java_value_to_ruby(value)
|
315
|
+
end
|
319
316
|
end
|
320
317
|
|
321
318
|
def to_hash
|
@@ -325,6 +322,15 @@ module AppEngine
|
|
325
322
|
hash
|
326
323
|
end
|
327
324
|
end
|
325
|
+
|
326
|
+
def java_value_to_ruby(prop)
|
327
|
+
ruby_type = SPECIAL_JAVA_TYPES[prop.class]
|
328
|
+
if ruby_type
|
329
|
+
ruby_type.new_from_java(prop)
|
330
|
+
else
|
331
|
+
prop
|
332
|
+
end
|
333
|
+
end
|
328
334
|
end
|
329
335
|
|
330
336
|
SPECIAL_RUBY_TYPES = [Time, Text, Blob, ByteString, Link].freeze
|
data/lib/appengine-apis/sdk.rb
CHANGED
@@ -69,22 +69,25 @@ module AppEngine
|
|
69
69
|
# Returns File.join(sdk_directory, *pieces)
|
70
70
|
#
|
71
71
|
def sdk_path(*pieces)
|
72
|
-
puts "sdk_path(#{pieces.join('/')})"
|
73
72
|
unless @sdk_path
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
begin
|
74
|
+
require 'reggae'
|
75
|
+
@sdk_path = AppEngine::Jars::Path
|
76
|
+
rescue Exception
|
77
|
+
base_path = File.join(ENV['APPENGINE_JAVA_SDK'] || '', 'bin')
|
78
|
+
exec_paths = ENV['PATH'].split(File::PATH_SEPARATOR)
|
79
|
+
exec_paths << '/usr/local/appengine-java-sdk/bin'
|
80
|
+
exec_paths << 'c:\appengine-java-sdk\bin'
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
while !exec_paths.empty?
|
83
|
+
if File.exist?(File.join(base_path, 'appcfg.sh'))
|
84
|
+
@sdk_path = File.dirname(base_path)
|
85
|
+
return File.join(@sdk_path, *pieces)
|
86
|
+
end
|
87
|
+
base_path = exec_paths.shift
|
84
88
|
end
|
85
|
-
|
89
|
+
raise "Unable to locate the Google App Engine SDK for Java."
|
86
90
|
end
|
87
|
-
raise "Unable to locate the Google App Engine SDK for Java."
|
88
91
|
end
|
89
92
|
File.join(@sdk_path, *pieces)
|
90
93
|
end
|
@@ -126,8 +126,7 @@ module AppEngine
|
|
126
126
|
#
|
127
127
|
# You may call this multiple times to reset to a new in-memory datastore.
|
128
128
|
def install_test_datastore
|
129
|
-
|
130
|
-
delegate = factory.create
|
129
|
+
delegate = install_api_stubs
|
131
130
|
lds = Java.ComGoogleAppengineApiDatastoreDev.LocalDatastoreService
|
132
131
|
|
133
132
|
delegate.set_property(
|
@@ -149,9 +148,15 @@ module AppEngine
|
|
149
148
|
# instead of dev_appserver. In that case you will need to install
|
150
149
|
# and configure a test environment for each request.
|
151
150
|
def install_api_stubs
|
151
|
+
current_delegate = ApiProxy.delegate
|
152
|
+
current_delegate.stop if current_delegate.respond_to? :stop
|
153
|
+
|
152
154
|
self.app_dir = '.' if app_dir.nil?
|
153
155
|
delegate = factory.create
|
154
156
|
ApiProxy::setDelegate(delegate)
|
157
|
+
at_exit do
|
158
|
+
delegate.stop
|
159
|
+
end
|
155
160
|
delegate
|
156
161
|
end
|
157
162
|
|
data/lib/appengine-apis/users.rb
CHANGED
@@ -78,16 +78,30 @@ module AppEngine
|
|
78
78
|
alias == equals?
|
79
79
|
alias to_s toString
|
80
80
|
|
81
|
-
|
81
|
+
class << self
|
82
|
+
alias java_new new # :nodoc:
|
83
|
+
|
82
84
|
# Creates a new User.
|
83
85
|
#
|
84
86
|
# Args:
|
85
87
|
# - email: a non-nil email address.
|
86
|
-
# - auth_domain:
|
88
|
+
# - auth_domain: an optinoal domain name into which this user has
|
87
89
|
# authenticated, or "gmail.com" for normal Google authentication.
|
88
|
-
def
|
90
|
+
def new(email, auth_domain=nil)
|
91
|
+
unless auth_domain
|
92
|
+
env = AppEngine::ApiProxy.current_environment
|
93
|
+
auth_domain = if env
|
94
|
+
env.getAuthDomain
|
95
|
+
else
|
96
|
+
'gmail.com'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
java_new(email, auth_domain)
|
89
101
|
end
|
90
|
-
|
102
|
+
end
|
103
|
+
|
104
|
+
if nil # rdoc only
|
91
105
|
# Return this user's nickname. The nickname will be a unique, human
|
92
106
|
# readable identifier for this user with respect to this application.
|
93
107
|
# It will be an email address for some users, but not all.
|
data/lib/appengine-apis.rb
CHANGED
data/spec/datastore_spec.rb
CHANGED
@@ -35,6 +35,16 @@ describe AppEngine::Datastore do
|
|
35
35
|
stored[:b].should == "b"
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should support Text" do
|
39
|
+
entity = Datastore::Entity.new("Test")
|
40
|
+
entity[:a] = Datastore::Text.new("a")
|
41
|
+
Datastore.put(entity)
|
42
|
+
stored = Datastore.get(entity.key)
|
43
|
+
stored[:a].should be_a(Datastore::Text)
|
44
|
+
stored[:a].should == "a"
|
45
|
+
stored.to_hash['a'].should == "a"
|
46
|
+
end
|
47
|
+
|
38
48
|
it "should put many" do
|
39
49
|
a = Datastore::Entity.new("A")
|
40
50
|
b = Datastore::Entity.new("B")
|
@@ -115,6 +125,13 @@ describe AppEngine::Datastore::Query do
|
|
115
125
|
'name', Query::EQUAL, 'Bob').should == q
|
116
126
|
end
|
117
127
|
|
128
|
+
it 'should support symbol ops' do
|
129
|
+
q = Query.new("Foo")
|
130
|
+
q.set_ancestor(@a.key).sort('name').filter(
|
131
|
+
'name', :==, 'aa')
|
132
|
+
q.fetch.to_a.should == [@aa]
|
133
|
+
end
|
134
|
+
|
118
135
|
it "should support ancestor" do
|
119
136
|
a = @a.key
|
120
137
|
q = Query.new("A", a)
|
@@ -207,3 +207,11 @@ describe AppEngine::Datastore::Entity do
|
|
207
207
|
@entity.to_hash.should == props
|
208
208
|
end
|
209
209
|
end
|
210
|
+
|
211
|
+
describe AppEngine::Datastore::Text do
|
212
|
+
it "should support to_s" do
|
213
|
+
t = AppEngine::Datastore::Text.new("foo")
|
214
|
+
t.to_s.should == t
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
data/spec/users_spec.rb
CHANGED
@@ -55,4 +55,15 @@ describe AppEngine::Users do
|
|
55
55
|
login.should =~ /foobar/
|
56
56
|
logout.should =~ /foobaz/
|
57
57
|
end
|
58
|
+
|
59
|
+
it 'should support new without auth domain' do
|
60
|
+
user = AppEngine::Users::User.new('foo@example.com')
|
61
|
+
user.auth_domain.should == 'gmail.com'
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
it 'should support new with auth domain' do
|
66
|
+
user = AppEngine::Users::User.new('foo@example.com', 'example.com')
|
67
|
+
user.auth_domain.should == 'example.com'
|
68
|
+
end
|
58
69
|
end
|
metadata
CHANGED
@@ -10,11 +10,10 @@ email:
|
|
10
10
|
cert_chain: []
|
11
11
|
|
12
12
|
summary: APIs and utilities for using JRuby on Google App Engine
|
13
|
-
post_install_message:
|
13
|
+
post_install_message:
|
14
14
|
extra_rdoc_files:
|
15
15
|
- History.txt
|
16
16
|
- Manifest.txt
|
17
|
-
- PostInstall.txt
|
18
17
|
- README.rdoc
|
19
18
|
homepage: http://code.google.com/p/appengine-jruby
|
20
19
|
signing_key:
|
@@ -38,7 +37,6 @@ default_executable:
|
|
38
37
|
files:
|
39
38
|
- History.txt
|
40
39
|
- Manifest.txt
|
41
|
-
- PostInstall.txt
|
42
40
|
- README.rdoc
|
43
41
|
- Rakefile
|
44
42
|
- lib/appengine-apis.rb
|
@@ -80,12 +78,12 @@ requirements: []
|
|
80
78
|
|
81
79
|
authors:
|
82
80
|
- Ryan Brown
|
83
|
-
date: 2009-
|
81
|
+
date: 2009-05-06 07:00:00 +00:00
|
84
82
|
platform: ruby
|
85
83
|
test_files: []
|
86
84
|
|
87
85
|
version: !ruby/object:Gem::Version
|
88
|
-
version: 0.0.
|
86
|
+
version: 0.0.4
|
89
87
|
require_paths:
|
90
88
|
- lib
|
91
89
|
dependencies:
|
data/PostInstall.txt
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
|
2
|
-
To use the local datastore you need to have the Google App Engine SDK for Java
|
3
|
-
installed
|
4
|
-
(http://code.google.com/appengine/docs/java/gettingstarted/installing.html).
|
5
|
-
Then you need to add several jars to your classpath.
|
6
|
-
|
7
|
-
For example:
|
8
|
-
$ export SDK=`pwd`/appengine-java-sdk/lib
|
9
|
-
$ export CLASSPATH=$SDK/shared/appengine-local-runtime-shared.jar:$SDK/impl/appengine-api-stubs.jar:$SDK/impl/appengine-api.jar:$SDK/impl/appengine-local-runtime.jar
|
10
|
-
|
11
|
-
For more information on appengine-apis, see
|
12
|
-
http://code.google.com/p/appengine-jruby
|