appoxy-simple_record 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +52 -0
- data/bin/simple_record +3 -0
- data/test/my_child_model.rb +6 -0
- data/test/my_model.rb +11 -0
- data/test/temp_test.rb +63 -0
- data/test/test_simple_record.rb +120 -0
- metadata +57 -0
data/README.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= simple_record
|
2
|
+
|
3
|
+
http://code.google.com/p/simple-record/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
An ActiveRecord interface for SimpleDB that takes care of offsets and padding, etc.
|
8
|
+
Can be used as a drop in replacement for ActiveRecord in rails.
|
9
|
+
|
10
|
+
Special thanks to Garrett Cox for creating Activerecord2sdb which SimpleRecord is based on:
|
11
|
+
http://activrecord2sdb.rubyforge.org/
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* FIX (list of features or problems)
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
|
19
|
+
FIX (code sample of usage)
|
20
|
+
|
21
|
+
== REQUIREMENTS:
|
22
|
+
|
23
|
+
* FIX (list of requirements)
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
sudo gem install activesupport right_aws local_cache
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Copyright (c) 2009 FIX
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
36
|
+
a copy of this software and associated documentation files (the
|
37
|
+
'Software'), to deal in the Software without restriction, including
|
38
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
39
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
40
|
+
permit persons to whom the Software is furnished to do so, subject to
|
41
|
+
the following conditions:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be
|
44
|
+
included in all copies or substantial portions of the Software.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
47
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
48
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
49
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
50
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
51
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
52
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/simple_record
ADDED
data/test/my_model.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
|
2
|
+
|
3
|
+
class MyModel < SimpleRecord::Base
|
4
|
+
|
5
|
+
has_attributes :created, :updated, :name, :age, :cool, :birthday
|
6
|
+
are_ints :age
|
7
|
+
are_booleans :cool
|
8
|
+
are_dates :created, :updated, :birthday
|
9
|
+
|
10
|
+
|
11
|
+
end
|
data/test/temp_test.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# rubymine won't run 1.9 tests
|
2
|
+
|
3
|
+
require 'minitest/unit'
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
|
5
|
+
require "yaml"
|
6
|
+
require 'right_aws'
|
7
|
+
require 'my_model'
|
8
|
+
require 'my_child_model'
|
9
|
+
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@config = YAML::load(File.read('test-config.yml'))
|
13
|
+
puts 'akey=' + @config['amazon']['access_key']
|
14
|
+
puts 'skey=' + @config['amazon']['secret_key']
|
15
|
+
RightAws::ActiveSdb.establish_connection(@config['amazon']['access_key'], @config['amazon']['secret_key'], :port=>80, :protocol=>"http")
|
16
|
+
SimpleRecord::Base.set_domain_prefix("simplerecord_tests_")
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
RightAws::ActiveSdb.close_connection()
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_dates
|
24
|
+
mm = MyModel.new
|
25
|
+
mm.name = "Travis"
|
26
|
+
mm.age = 32
|
27
|
+
mm.cool = true
|
28
|
+
mm.created = DateTime.now - 10
|
29
|
+
mm.updated = DateTime.now
|
30
|
+
mm.birthday = Time.now - (3600 * 24 * 365 * 10)
|
31
|
+
puts 'before save=' + mm.inspect
|
32
|
+
mm.save
|
33
|
+
puts 'after save=' + mm.inspect
|
34
|
+
|
35
|
+
mms = MyModel.find(:all, :conditions => ["created > ?", DateTime.now - 1])
|
36
|
+
puts 'mms=' + mms.inspect
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_date_comparisons
|
41
|
+
|
42
|
+
t = SimpleRecord::Base.pad_and_offset(Time.now)
|
43
|
+
puts t
|
44
|
+
dt = SimpleRecord::Base.pad_and_offset(DateTime.now)
|
45
|
+
puts dt
|
46
|
+
dt_tomorrow = SimpleRecord::Base.pad_and_offset(DateTime.now + 1)
|
47
|
+
|
48
|
+
|
49
|
+
puts 'compare=' + (t <=> dt).to_s
|
50
|
+
puts 'compare=' + (t <=> dt_tomorrow).to_s
|
51
|
+
|
52
|
+
dts = DateTime.parse(dt_tomorrow)
|
53
|
+
puts dts.to_s
|
54
|
+
ts = Time.parse(dt)
|
55
|
+
puts ts.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
setup
|
59
|
+
|
60
|
+
#test_dates
|
61
|
+
test_date_comparisons
|
62
|
+
|
63
|
+
teardown
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'minitest/unit'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
|
3
|
+
require "yaml"
|
4
|
+
require 'right_aws'
|
5
|
+
require 'my_model'
|
6
|
+
require 'my_child_model'
|
7
|
+
|
8
|
+
class TestSimpleRecord < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@config = YAML::load(File.read('test-config.yml'))
|
12
|
+
puts 'akey=' + @config['amazon']['access_key']
|
13
|
+
puts 'skey=' + @config['amazon']['secret_key']
|
14
|
+
RightAws::ActiveSdb.establish_connection(@config['amazon']['access_key'], @config['amazon']['secret_key'], :port=>80, :protocol=>"http")
|
15
|
+
SimpleRecord::Base.set_domain_prefix("simplerecord_tests_")
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
RightAws::ActiveSdb.close_connection()
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_save_get
|
23
|
+
mm = MyModel.new
|
24
|
+
mm.name = "Travis"
|
25
|
+
mm.age = 32
|
26
|
+
mm.cool = true
|
27
|
+
mm.save
|
28
|
+
id = mm.id
|
29
|
+
puts 'id=' + id.to_s
|
30
|
+
# Get the object back
|
31
|
+
mm2 = MyModel.find(id)
|
32
|
+
puts 'got=' + mm2.name + ' and he/she is ' + mm2.age.to_s + ' years old and he/she is cool? ' + mm2.cool.to_s
|
33
|
+
puts mm2.cool.class.name
|
34
|
+
assert mm2.id == mm.id
|
35
|
+
assert mm2.age == mm.age
|
36
|
+
assert mm2.cool == mm.cool
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_bad_query
|
40
|
+
mm2 = MyModel.find(:all, :conditions=>["name =4?", "1"])
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_batch_save
|
44
|
+
items = []
|
45
|
+
mm = MyModel.new
|
46
|
+
mm.name = "Travis"
|
47
|
+
mm.age = 32
|
48
|
+
mm.cool = true
|
49
|
+
items << mm
|
50
|
+
mm = MyModel.new
|
51
|
+
mm.name = "Tritt"
|
52
|
+
mm.age = 44
|
53
|
+
mm.cool = false
|
54
|
+
items << mm
|
55
|
+
MyModel.batch_save(items)
|
56
|
+
items.each do |item|
|
57
|
+
puts 'id=' + item.id
|
58
|
+
new_item = MyModel.find(item.id)
|
59
|
+
puts 'new=' + new_item.inspect
|
60
|
+
assert item.id == new_item.id
|
61
|
+
assert item.name == new_item.name
|
62
|
+
assert item.cool == new_item.cool
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Testing getting the association ID without materializing the obejct
|
67
|
+
def test_get_belongs_to_id
|
68
|
+
mm = MyModel.new
|
69
|
+
mm.name = "Parent"
|
70
|
+
mm.age = 55
|
71
|
+
mm.cool = true
|
72
|
+
mm.save
|
73
|
+
|
74
|
+
child = MyChildModel.new
|
75
|
+
child.name = "Child"
|
76
|
+
child.my_model = mm
|
77
|
+
child.save
|
78
|
+
|
79
|
+
child = MyChildModel.find(child.id)
|
80
|
+
puts child.my_model_id
|
81
|
+
assert child.my_model_id == mm.id
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_callbacks
|
85
|
+
# these DO NOT work right now, all objects get all callbacks
|
86
|
+
# I tried like this, seem to be getting somewhere.
|
87
|
+
#
|
88
|
+
# class << self;
|
89
|
+
# @@callbacks.each do |callback|
|
90
|
+
# #we first have to make an initialized array for each of the callbacks, to prevent problems if they are not called
|
91
|
+
# puts 'setting callback ' + callback.to_s + ' on ' + self.inspect
|
92
|
+
# eval %{
|
93
|
+
#
|
94
|
+
# # add the methods to the class
|
95
|
+
# def #{callback}(*args)
|
96
|
+
# args.each do |arg|
|
97
|
+
# cb_names = self.instance_variable_get(:@#{callback}_names)
|
98
|
+
# cb_names = [] if cb_names.nil?
|
99
|
+
# cb_names << arg.to_s if cb_names.index(arg.to_s).nil?
|
100
|
+
# self.instance_variable_set(:@#{callback}_names, cb_names)
|
101
|
+
# end
|
102
|
+
## asdf @@#{callback}_names=args.map{|arg| arg.to_s}
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# # now we run the methods in the callback array for this class
|
106
|
+
#send :define_method, "run_#{callback}" do
|
107
|
+
## def run_#{callback}
|
108
|
+
# cb_names = self.instance_variable_get(:@#{callback}_names)
|
109
|
+
# cb_names.each { |name|
|
110
|
+
# unless eval(name)
|
111
|
+
# return false
|
112
|
+
# end
|
113
|
+
# }
|
114
|
+
# return true
|
115
|
+
# end
|
116
|
+
# }
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appoxy-simple_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Reeder
|
8
|
+
- RightScale
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-06-06 00:00:00 -07:00
|
14
|
+
default_executable: simple_record
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Drop in replacement for ActiveRecord to Amazon SimpleDB instead.
|
18
|
+
email: travis@appoxy.com
|
19
|
+
executables:
|
20
|
+
- simple_record
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.txt
|
25
|
+
files:
|
26
|
+
- README.txt
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://github.com/appoxy/simple_record/
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- --charset=UTF-8
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: "0"
|
39
|
+
version:
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.2.0
|
50
|
+
signing_key:
|
51
|
+
specification_version: 2
|
52
|
+
summary: Drop in replacement for ActiveRecord to Amazon SimpleDB instead.
|
53
|
+
test_files:
|
54
|
+
- test/my_child_model.rb
|
55
|
+
- test/my_model.rb
|
56
|
+
- test/temp_test.rb
|
57
|
+
- test/test_simple_record.rb
|