machu-appengine-pstore 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 MATSUOKA Kohei
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = appengine-pstore
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 MATSUOKA Kohei. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "appengine-pstore"
8
+ gem.summary = %Q{TODO: one-line summary of your gem}
9
+ gem.description = %Q{TODO: longer description of your gem}
10
+ gem.email = "kohei@machu.jp"
11
+ gem.homepage = "http://github.com/machu/appengine-pstore"
12
+ gem.authors = ["MATSUOKA Kohei"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "appengine-pstore #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'appengine-apis/datastore'
3
+
4
+ module AppEngine
5
+ module Datastore
6
+ class Query
7
+ def keysonly
8
+ @query.set_keys_only
9
+ self
10
+ end
11
+
12
+ def keysonly?
13
+ @query.is_keys_only
14
+ end
15
+ end
16
+ end
17
+
18
+ class PStore
19
+ def initialize(dbname)
20
+ @kind = self.class.name
21
+ @parent_key = AppEngine::Datastore::Key.from_path(@kind, dbname)
22
+ @transaction = nil
23
+ end
24
+
25
+ def in_transaction
26
+ unless AppEngine::Datastore.current_transaction(nil)
27
+ raise PStore::Error, "not in transaction"
28
+ end
29
+ end
30
+
31
+ def in_transaction_wr
32
+ in_transaction
33
+ raise PStore::Error, "in read-only transaction" if @rdonly
34
+ end
35
+ private :in_transaction, :in_transaction_wr
36
+
37
+ def transaction(readonly = false)
38
+ @rdonly = readonly
39
+ @transaction = AppEngine::Datastore.begin_transaction
40
+ @cache = {}
41
+ yield self
42
+ @transaction.commit
43
+ @transaction = nil
44
+ end
45
+
46
+ def [](name)
47
+ in_transaction
48
+ raise PStore::Error, "in read-only transaction" if @rdonly
49
+ if @cache.key?(name)
50
+ @cache[name] # return latest put data
51
+ else
52
+ key = AppEngine::Datastore::Key.from_path(@parent_key, @kind, name)
53
+ entity = AppEngine::Datastore.get(@transaction, key)
54
+ load(entity[:value])
55
+ end
56
+ end
57
+
58
+ def []=(name, value)
59
+ in_transaction_wr
60
+ entity = AppEngine::Datastore::Entity.new(@kind, name, @parent_key)
61
+ entity[:value] = dump(value)
62
+ AppEngine::Datastore.put(@transaction, entity)
63
+ @cache[name] = value
64
+ value
65
+ end
66
+
67
+ def delete(name)
68
+ key = AppEngine::Datastore::Key.from_path(@parent_key, @kind, name)
69
+ AppEngine::Datastore.delete(@transaction, key)
70
+ @cache.delete(name)
71
+ end
72
+
73
+ def load(content)
74
+ Marshal::load(content)
75
+ end
76
+
77
+ def dump(content)
78
+ Marshal::dump(content)
79
+ end
80
+
81
+ def roots
82
+ in_transaction
83
+ query = AppEngine::Datastore::Query.new(@kind, @parent_key)
84
+ query.keysonly.fetch.map {|value|
85
+ value.key.name
86
+ }.concat(@cache.keys).uniq
87
+ end
88
+
89
+ def root?(key)
90
+ in_transaction
91
+ end
92
+
93
+ def path
94
+ @parent_key
95
+ end
96
+ end
97
+ end
98
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "AppenginePstore" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'appengine-pstore'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: machu-appengine-pstore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - MATSUOKA Kohei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: "TODO: longer description of your gem"
26
+ email: kohei@machu.jp
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/appengine-pstore.rb
42
+ - spec/appengine-pstore_spec.rb
43
+ - spec/spec_helper.rb
44
+ has_rdoc: false
45
+ homepage: http://github.com/machu/appengine-pstore
46
+ licenses:
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: "TODO: one-line summary of your gem"
71
+ test_files:
72
+ - spec/appengine-pstore_spec.rb
73
+ - spec/spec_helper.rb