activerecord-datastore-adapter 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activerecord-datastore-adapter (0.0.1)
5
- activerecord (>= 3.0.3)
4
+ activerecord-datastore-adapter (0.0.3)
5
+ activerecord (= 3.0.6)
6
6
  appengine-apis (= 0.0.22)
7
7
  arel (>= 2.0.7)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activemodel (3.0.5)
13
- activesupport (= 3.0.5)
12
+ activemodel (3.0.6)
13
+ activesupport (= 3.0.6)
14
14
  builder (~> 2.1.2)
15
- i18n (~> 0.4)
16
- activerecord (3.0.5)
17
- activemodel (= 3.0.5)
18
- activesupport (= 3.0.5)
15
+ i18n (~> 0.5.0)
16
+ activerecord (3.0.6)
17
+ activemodel (= 3.0.6)
18
+ activesupport (= 3.0.6)
19
19
  arel (~> 2.0.2)
20
20
  tzinfo (~> 0.3.23)
21
- activesupport (3.0.5)
21
+ activesupport (3.0.6)
22
22
  appengine-apis (0.0.22)
23
23
  appengine-rack
24
24
  appengine-rack (0.0.12)
@@ -45,7 +45,6 @@ GEM
45
45
 
46
46
  PLATFORMS
47
47
  java
48
- ruby
49
48
 
50
49
  DEPENDENCIES
51
50
  activerecord-datastore-adapter!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 siddick.com
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.textile CHANGED
@@ -2,13 +2,14 @@ h1. Datastore Adapter
2
2
 
3
3
  ActiveRecord Adatper for AppEngine Datastore. The AppEngine Datastore is not a relational database system. So, this adapter only support some basic features.
4
4
 
5
- h2. Installation( under-construction )
5
+ h2. Installation
6
6
 
7
7
  Use appengine-sdk (1.4.0)
8
8
 
9
9
  Create Rails 3 application:
10
10
 
11
- bc. rails new app_name -m http://siddick.github.com/datastore/rails3.rb
11
+ bc. gem install rails --version=3.0.6
12
+ rails new app_name -m http://siddick.github.com/datastore/rails3.rb
12
13
  cd app_name
13
14
  appcfg.rb run bin/rails g scaffold post title:string content:text
14
15
  appcfg.rb run bin/rake db:migrate
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "activerecord-datastore-adapter"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.3"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Mohammed Siddick"]
9
9
  s.email = ["siddick@gmail.com"]
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency( 'appengine-apis', '0.0.22' )
23
- s.add_dependency( 'activerecord', '>= 3.0.3' )
23
+ s.add_dependency( 'activerecord', '3.0.6' )
24
24
  s.add_dependency( 'arel', '>= 2.0.7' )
25
25
  end
data/examples/rails3.rb CHANGED
@@ -7,31 +7,19 @@ disable_system_gems
7
7
  disable_rubygems
8
8
  bundle_path ".gems/bundler_gems"
9
9
 
10
- gem 'rails', '~> 3.0.5'
11
- gem 'activerecord-datastore-adapter'
10
+ gem 'rails', '3.0.6'
11
+ gem 'activerecord-datastore-adapter', '>= 0.0.3'
12
12
  gem 'jruby-rack', '1.0.5'
13
13
 
14
14
  GEMFILE
15
15
  end
16
16
 
17
- remove_file 'config/boot.rb'
18
- create_file 'config/boot.rb' do
19
- <<-BOOT
20
-
21
- String.class_eval do
22
- alias :old_plus :+
23
- def +( val )
24
- if( val.is_a? Array )
25
- [ self ] + val
26
- else
27
- old_plus val
28
- end
29
- end
30
- end
31
- BOOT
17
+ gsub_file 'config/boot.rb', /^/ do
18
+ "# "
32
19
  end
33
20
 
34
21
 
22
+
35
23
  remove_file 'config/database.yml'
36
24
  create_file 'config/database.yml' do
37
25
  <<-DATABASE
@@ -60,6 +48,22 @@ gsub_file 'config/application.rb', /class Application < Rails::Application$/ do
60
48
  "
61
49
  end
62
50
 
51
+ create_file 'config/initializers/rails_patch.rb' do
52
+ <<-BOOT
53
+
54
+ String.class_eval do
55
+ alias :old_plus :+
56
+ def +( val )
57
+ if( val.is_a? Array )
58
+ [ self ] + val
59
+ else
60
+ old_plus val
61
+ end
62
+ end
63
+ end
64
+ BOOT
65
+ end
66
+
63
67
  create_file 'config/initializers/cache_store.rb' do
64
68
  <<-CACHE_STORE
65
69
  #require 'appengine-apis/memcache'
@@ -7,39 +7,15 @@ disable_system_gems
7
7
  disable_rubygems
8
8
  bundle_path ".gems/bundler_gems"
9
9
 
10
- gem 'rails', '~> 3.0.5'
11
- gem 'appengine-apis', '>= 0.0.22'
10
+ gem 'rails', '3.0.6'
11
+ gem 'activerecord-datastore-adapter', :git => 'git://github.com/siddick/datastore.git'
12
+ gem 'jruby-rack', '1.0.5'
12
13
 
13
14
  GEMFILE
14
15
  end
15
16
 
16
- remove_file 'config/boot.rb'
17
- create_file 'config/boot.rb' do
18
- <<-BOOT
19
-
20
- String.class_eval do
21
- alias :old_plus :+
22
- def +( val )
23
- if( val.is_a? Array )
24
- [ self ] + val
25
- else
26
- old_plus val
27
- end
28
- end
29
- end
30
-
31
- File.class_eval do
32
- class << self
33
- alias :old_expand_path :expand_path
34
- def expand_path( *args )
35
- fn = old_expand_path( *args )
36
- fn.sub(/^.*file:/, 'file:') if fn
37
- end
38
- end
39
- end
40
-
41
- $LOAD_PATH.push( '../../lib' )
42
- BOOT
17
+ gsub_file 'config/boot.rb', /^/ do
18
+ "# "
43
19
  end
44
20
 
45
21
  remove_file 'config/database.yml'
@@ -47,15 +23,15 @@ create_file 'config/database.yml' do
47
23
  <<-DATABASE
48
24
  development:
49
25
  adapter: datastore
50
- database: development.yml
26
+ database: db/database.yml
51
27
 
52
28
  test:
53
29
  adapter: datastore
54
- database: test.yml
30
+ database: db/test.yml
55
31
 
56
32
  production:
57
33
  adapter: datastore
58
- database: development.yml
34
+ database: db/database.yml
59
35
  DATABASE
60
36
  end
61
37
 
@@ -70,6 +46,22 @@ gsub_file 'config/application.rb', /class Application < Rails::Application$/ do
70
46
  "
71
47
  end
72
48
 
49
+ create_file 'config/initializers/rails_patch.rb' do
50
+ <<-BOOT
51
+
52
+ String.class_eval do
53
+ alias :old_plus :+
54
+ def +( val )
55
+ if( val.is_a? Array )
56
+ [ self ] + val
57
+ else
58
+ old_plus val
59
+ end
60
+ end
61
+ end
62
+ BOOT
63
+ end
64
+
73
65
  create_file 'config/initializers/cache_store.rb' do
74
66
  <<-CACHE_STORE
75
67
  #require 'appengine-apis/memcache'
@@ -17,6 +17,13 @@ module ActiveRecord
17
17
  end
18
18
 
19
19
  module ConnectionAdapters
20
+
21
+ class DataStoreColumn < Column
22
+ def self.binary_to_string value
23
+ AppEngine::Datastore::Blob.new(value)
24
+ end
25
+ end
26
+
20
27
  class DatastoreAdapter < AbstractAdapter
21
28
  ADAPTER_NAME = "Datastore"
22
29
 
@@ -114,7 +121,7 @@ module ActiveRecord
114
121
  def columns( table_name, name = nil)
115
122
  @connection.columns( table_name, name ).collect{|k,opt|
116
123
  is_primary = opt["type"] == "primary_key"
117
- c = Column.new( k, opt["default"], is_primary ? "integer" : opt["type"].to_s, opt["null"] )
124
+ c = DataStoreColumn.new( k, opt["default"], is_primary ? "integer" : opt["type"].to_s, opt["null"] )
118
125
  c.primary = true if is_primary
119
126
  c
120
127
  }
@@ -58,7 +58,9 @@ module Arel
58
58
  :integer => lambda{|k,i| i.to_i },
59
59
  :datetime => lambda{|k,t| t.is_a?(Time)? t : Time.parse(t.to_s) },
60
60
  :date => lambda{|k,t| t.is_a?(Date)? t : Date.parse(t.to_s) },
61
- :float => lambda{|k,f| f.to_f }
61
+ :float => lambda{|k,f| f.to_f },
62
+ :text => lambda{|k,t| AppEngine::Datastore::Text.new(t) },
63
+ :binary => lambda{|k,t| AppEngine::Datastore::Blob.new(t) }
62
64
  }
63
65
  InScan = /'((\\.|[^'])*)'|(\d+)/
64
66
  def apply_filter( key, opt, value )
@@ -123,9 +125,13 @@ module Arel
123
125
  QString.new( @connection, c.froms.name, get_limit_and_offset(o) ).wheres( c.wheres ).orders(o.orders).projections( c.projections )
124
126
  end
125
127
 
128
+ def insert_type_case( value )
129
+ value.is_a?( ActiveSupport::TimeWithZone ) ? value.time : value
130
+ end
131
+
126
132
  def visit_Arel_Nodes_InsertStatement o
127
133
  e = AppEngine::Datastore::Entity.new(o.relation.name)
128
- o.columns.each_with_index{|c,i| e[c.name] = o.values.left[i] }
134
+ o.columns.each_with_index{|c,i| e[c.name] = insert_type_case(o.values.left[i]) }
129
135
  e
130
136
  end
131
137
 
@@ -9,6 +9,7 @@ class User < ActiveRecord::Base
9
9
  t.datetime :dob
10
10
  t.integer :rating
11
11
  t.float :score
12
+ t.binary :data
12
13
 
13
14
  t.timestamps
14
15
  end
@@ -40,4 +41,24 @@ describe Person do
40
41
  users = User.where( " rating >= 1 and rating <= 3 " )
41
42
  users.all.size.should == 3
42
43
  end
44
+
45
+ it "check integer" do
46
+ user = User.create!( :name => "guest", :rating => "5a" )
47
+ user = User.find( user.id )
48
+ user.rating.should == 5
49
+ end
50
+
51
+ it "check datetime" do
52
+ user = User.create!( :name => "guest", :dob => "24 may, 2010" )
53
+ user = User.find( user.id )
54
+ user.dob.strftime("%Y-%m-%d").should == "2010-05-24"
55
+ end
56
+
57
+ it "check binary" do
58
+ user = User.create!( :name => "guest", :dob => "24 may, 2010", :data => "testing" )
59
+ user.data.class.should == AppEngine::Datastore::Blob
60
+ user = User.find_by_name( "guest" )
61
+ user.data.should == "testing"
62
+ user.data.class.should == AppEngine::Datastore::Blob
63
+ end
43
64
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: activerecord-datastore-adapter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mohammed Siddick
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-06 00:00:00 +05:30
13
+ date: 2011-04-11 00:00:00 +05:30
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
- - - ">="
33
+ - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.0.3
35
+ version: 3.0.6
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -61,11 +61,12 @@ files:
61
61
  - .gitignore
62
62
  - Gemfile
63
63
  - Gemfile.lock
64
+ - MIT-LICENSE
64
65
  - README.textile
65
66
  - Rakefile
66
67
  - activerecord-datastore-adapter.gemspec
67
68
  - examples/rails3.rb
68
- - examples/rails3_local.rb
69
+ - examples/rails3_edge.rb
69
70
  - lib/active_record/connection_adapters/datastore_adapter.rb
70
71
  - lib/active_record/datastore_associations_patch.rb
71
72
  - lib/arel/visitors/datastore.rb