machu-appengine-pstore 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,11 +1,42 @@
1
1
  = appengine-pstore
2
2
 
3
- * http://github.com/machu/appengine-pstore
3
+ * http://github.com/machu/appengine-pstore
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
7
  The PStore interfaces for the Google App Engine Datastore.
8
8
 
9
+ == SYNOPSIS
10
+
11
+ You can use the Google App Engine Datastore like PStore.
12
+
13
+ db = AppEngine::PStore.new('database.pstore')
14
+ db.transaction do |db|
15
+ db[:key1] = "value1"
16
+ db[:key2] = "value2"
17
+ end
18
+
19
+ db.transaction do |db|
20
+ puts db[:key1] # => "value1"
21
+ end
22
+
23
+ == NOTE
24
+
25
+ A database has following limits.
26
+
27
+ * maximum key count: 1,000 keys
28
+ * maximum value size: 1MB
29
+
30
+ == INSTALL
31
+
32
+ This module is hosted by gems.github.com.
33
+
34
+ sudo gem install machu-appengine-pstore --source http://gems.github.com
35
+
36
+ == DEPENDENCIES
37
+
38
+ This library depends on appengine-apis.
39
+
9
40
  == Copyright
10
41
 
11
42
  Copyright (c) 2009 MATSUOKA Kohei. See LICENSE for details.
data/Rakefile CHANGED
@@ -5,12 +5,13 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "appengine-pstore"
8
- gem.summary = %Q{PStore compatible interface for Google Apps Engine.}
9
- gem.description = %Q{PStore compatible interface for Google Apps Engine.}
8
+ gem.summary = %Q{The PStore interfaces for the Google App Engine Datastore.}
9
+ gem.description = %Q{The PStore interfaces for the Google App Engine Datastore.}
10
10
  gem.email = "kohei@machu.jp"
11
11
  gem.homepage = "http://github.com/machu/appengine-pstore"
12
12
  gem.authors = ["MATSUOKA Kohei"]
13
13
  gem.add_development_dependency "rspec"
14
+ gem.add_dependency "appengine-apis"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{appengine-pstore}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["MATSUOKA Kohei"]
12
- s.date = %q{2009-09-27}
13
- s.description = %q{PStore compatible interface for Google Apps Engine.}
12
+ s.date = %q{2009-09-28}
13
+ s.description = %q{The PStore interfaces for the Google App Engine Datastore.}
14
14
  s.email = %q{kohei@machu.jp}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
34
  s.rubygems_version = %q{1.3.5}
35
- s.summary = %q{PStore compatible interface for Google Apps Engine.}
35
+ s.summary = %q{The PStore interfaces for the Google App Engine Datastore.}
36
36
  s.test_files = [
37
37
  "spec/appengine-pstore_spec.rb",
38
38
  "spec/spec_helper.rb"
@@ -44,10 +44,13 @@ Gem::Specification.new do |s|
44
44
 
45
45
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
46
  s.add_development_dependency(%q<rspec>, [">= 0"])
47
+ s.add_runtime_dependency(%q<appengine-apis>, [">= 0"])
47
48
  else
48
49
  s.add_dependency(%q<rspec>, [">= 0"])
50
+ s.add_dependency(%q<appengine-apis>, [">= 0"])
49
51
  end
50
52
  else
51
53
  s.add_dependency(%q<rspec>, [">= 0"])
54
+ s.add_dependency(%q<appengine-apis>, [">= 0"])
52
55
  end
53
56
  end
@@ -37,27 +37,45 @@ module AppEngine
37
37
  end
38
38
  end
39
39
 
40
+ # The PStore compatible interface for Google App Engine Datastore.
41
+ #
42
+ # db = AppEngine::PStore.new(dbname)
43
+ # db.transaction do |db|
44
+ # db[key] = value
45
+ # end
46
+ #
47
+ # A data is stored to the Datastore as AppEngine::Entity.
48
+ # The stracture of Datastore has following schema.
49
+ #
50
+ # * dbname: a root key for the Datastore.
51
+ # * key: A child of the root key.
52
+ # * value: AppEngine::Entity that contains the value object.
53
+ #
54
+ # Note: 'key' and 'value' are marshalled before putting Datastore.
55
+ #
40
56
  class PStore
57
+ # Create a database identified by dbname.
41
58
  def initialize(dbname)
42
59
  @kind = self.class.name
43
60
  @parent_key = AppEngine::Datastore::Key.from_path(@kind, dbname)
44
61
  @transaction = nil
45
62
  end
46
63
 
64
+ # Raises PStore::Error unless in a transaction.
47
65
  def in_transaction
48
66
  if @transaction == nil || @transaction.active? == false
49
- #unless transaction && transaction.active
50
- #unless AppEngine::Datastore.current_transaction(nil)
51
67
  raise ::PStore::Error, "not in transaction"
52
68
  end
53
69
  end
54
70
 
71
+ # Raises PStore::Error unless in a writable transaction.
55
72
  def in_transaction_wr
56
73
  in_transaction
57
74
  raise ::PStore::Error, "in read-only transaction" if @rdonly
58
75
  end
59
76
  private :in_transaction, :in_transaction_wr
60
77
 
78
+ # Begins a new transaction for the AppEngine::Datastore.
61
79
  def transaction(readonly = false)
62
80
  raise ::PStore::Error, "nested transaction" if @transaction
63
81
  @rdonly = readonly
@@ -81,18 +99,21 @@ module AppEngine
81
99
  end
82
100
  end
83
101
 
102
+ # Commit the transaction.
84
103
  def commit
85
104
  in_transaction
86
105
  @transaction.commit
87
106
  throw :pstore_abort_transaction
88
107
  end
89
108
 
109
+ # Abort the transaction.
90
110
  def abort
91
111
  in_transaction
92
112
  @transaction.rollback
93
113
  throw :pstore_abort_transaction
94
114
  end
95
115
 
116
+ # Retrieves a stored value from the Datastore by the name.
96
117
  def [](name)
97
118
  in_transaction
98
119
  # return uncommited data if exist
@@ -108,6 +129,7 @@ module AppEngine
108
129
  end
109
130
  end
110
131
 
132
+ # Stores a value to the Datastore by the name.
111
133
  def []=(name, value)
112
134
  in_transaction_wr
113
135
  entity = AppEngine::Datastore::Entity.new(@kind, dump(name), @parent_key)
@@ -118,6 +140,7 @@ module AppEngine
118
140
  value
119
141
  end
120
142
 
143
+ # Delete a value from the Datastore by the name.
121
144
  def delete(name)
122
145
  in_transaction_wr
123
146
  key = AppEngine::Datastore::Key.from_path(@parent_key, @kind, dump(name))
@@ -137,6 +160,7 @@ module AppEngine
137
160
  Marshal::dump(content)
138
161
  end
139
162
 
163
+ # Returns all keys of this database.
140
164
  def roots
141
165
  in_transaction
142
166
  query = AppEngine::Datastore::Query.new(@kind, @parent_key)
@@ -146,11 +170,13 @@ module AppEngine
146
170
  (db_keys + @uncommited[:added].keys - @uncommited[:deleted].keys).uniq
147
171
  end
148
172
 
173
+ # Whether the database has key.
149
174
  def root?(key)
150
175
  in_transaction
151
176
  self.roots.include?(key)
152
177
  end
153
178
 
179
+ # Returns the database's name
154
180
  def path
155
181
  @parent_key.name
156
182
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machu-appengine-pstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MATSUOKA Kohei
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-27 00:00:00 -07:00
12
+ date: 2009-09-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,17 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: PStore compatible interface for Google Apps Engine.
25
+ - !ruby/object:Gem::Dependency
26
+ name: appengine-apis
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: The PStore interfaces for the Google App Engine Datastore.
26
36
  email: kohei@machu.jp
27
37
  executables: []
28
38
 
@@ -68,7 +78,7 @@ rubyforge_project:
68
78
  rubygems_version: 1.3.5
69
79
  signing_key:
70
80
  specification_version: 3
71
- summary: PStore compatible interface for Google Apps Engine.
81
+ summary: The PStore interfaces for the Google App Engine Datastore.
72
82
  test_files:
73
83
  - spec/appengine-pstore_spec.rb
74
84
  - spec/spec_helper.rb