simple_record 1.1.17 → 1.1.20

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -14,14 +14,14 @@ An ActiveRecord interface for SimpleDB. Can be used as a drop in replacement fo
14
14
 
15
15
  1. Install gems
16
16
 
17
- ONE TIME: Be sure to add the new gemcutter source:
17
+ ONE TIME: Be sure to add the new gemcutter source:
18
18
 
19
- - gem install gemcutter
20
- - gem tumble
19
+ gem install gemcutter
20
+ gem tumble
21
21
 
22
- THEN (if you already have http://gemcutter.org in your sources and it MUST be above rubyforge.org):
22
+ THEN (you should have http://gemcutter.org in your sources and it MUST be above rubyforge.org):
23
23
 
24
- gem install aws uuidtools http_connection simple_record
24
+ gem install simple_record
25
25
 
26
26
  2. Create a model
27
27
 
data/lib/simple_record.rb CHANGED
@@ -81,11 +81,27 @@ module SimpleRecord
81
81
 
82
82
 
83
83
  def initialize(attrs={})
84
- super
85
- # Need to deal with objects passed in. iterate through belongs_to perhaps and if in attrs, set the objects id rather than the object itself
84
+ # todo: Need to deal with objects passed in. iterate through belongs_to perhaps and if in attrs, set the objects id rather than the object itself
85
+
86
+ if params[0]
87
+ #we have to handle the virtuals. Right now, this assumes that all parameters are passed from inside an array
88
+ #this is the usually the case when the parameters are passed passed via POST and obtained from the params array
89
+ @@virtuals.each do |virtual|
90
+ #we first copy the information for the virtual to an instance variable of the same name
91
+ eval("@#{virtual}=params[0]['#{virtual}']")
92
+ #and then remove the parameter before it is passed to initialize, so that it is NOT sent to SimpleDB
93
+ eval("params[0].delete('#{virtual}')")
94
+ end
95
+ super(*params)
96
+ else
97
+ super()
98
+ end
99
+ @errors=SimpleRecord_errors.new
100
+ @dirty = {}
86
101
  end
87
102
 
88
103
 
104
+
89
105
  # todo: move into Callbacks module
90
106
  #this bit of code creates a "run_blank" function for everything value in the @@callbacks array.
91
107
  #this function can then be inserted in the appropriate place in the save, new, destroy, etc overrides
@@ -472,27 +488,6 @@ module SimpleRecord
472
488
 
473
489
  def self.has_one(*args)
474
490
 
475
- end
476
-
477
- def initialize(*params)
478
-
479
- if params[0]
480
- #we have to handle the virtuals. Right now, this assumes that all parameters are passed from inside an array
481
- #this is the usually the case when the parameters are passed passed via POST and obtained from the params array
482
- @@virtuals.each do |virtual|
483
- #we first copy the information for the virtual to an instance variable of the same name
484
- eval("@#{virtual}=params[0]['#{virtual}']")
485
- #and then remove the parameter before it is passed to initialize, so that it is NOT sent to SimpleDB
486
- eval("params[0].delete('#{virtual}')")
487
- end
488
- super(*params)
489
- else
490
- super()
491
- end
492
- @errors=SimpleRecord_errors.new
493
- @dirty = {}
494
-
495
-
496
491
  end
497
492
 
498
493
  def clear_errors
@@ -1094,6 +1089,10 @@ module SimpleRecord
1094
1089
  find(:all, *params)
1095
1090
  end
1096
1091
 
1092
+ def empty?
1093
+ return load.empty?
1094
+ end
1095
+
1097
1096
  def build(*params)
1098
1097
  params[0][@referencename]=@referencevalue
1099
1098
  eval(@subname).new(*params)
data/lib/stats.rb CHANGED
@@ -1,16 +1,16 @@
1
- module SimpleRecord
2
- class Stats
3
- attr_accessor :selects, :puts
4
-
5
- def initialize
6
- @selects = 0
7
- @puts = 0
8
- end
9
-
10
- def clear
11
- self.selects = 0
12
- self.puts = 0
13
- end
14
- end
15
- end
16
-
1
+ module SimpleRecord
2
+ class Stats
3
+ attr_accessor :selects, :puts
4
+
5
+ def initialize
6
+ @selects = 0
7
+ @puts = 0
8
+ end
9
+
10
+ def clear
11
+ self.selects = 0
12
+ self.puts = 0
13
+ end
14
+ end
15
+ end
16
+
@@ -1,34 +1,34 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
2
- require 'my_model'
3
-
4
- class MyChildModel < SimpleRecord::Base
5
- belongs_to :my_model
6
- has_attributes :name, :child_attr
7
-
8
- end
9
-
10
-
11
- =begin
12
-
13
-
14
- puts 'word'
15
-
16
- mm = MyModel.new
17
- puts 'word2'
18
-
19
- mcm = MyChildModel.new
20
-
21
- puts 'mcm instance methods=' + MyChildModel.instance_methods(true).inspect
22
- #puts 'mcm=' + mcm.instance_methods(false)
23
- puts 'mcm class vars = ' + mcm.class.class_variables.inspect
24
- puts mcm.class == MyChildModel
25
- puts 'saved? ' + mm.save.to_s
26
- puts mm.errors.inspect
27
-
28
- puts "mm attributes=" + MyModel.defined_attributes.inspect
29
- puts "mcm attributes=" + MyChildModel.defined_attributes.inspect
30
-
31
- mcm2 = MyChildModel.new
32
- puts "mcm2 attributes=" + MyChildModel.defined_attributes.inspect
33
-
34
- =end
1
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/simple_record")
2
+ require 'my_model'
3
+
4
+ class MyChildModel < SimpleRecord::Base
5
+ belongs_to :my_model
6
+ has_attributes :name, :child_attr
7
+
8
+ end
9
+
10
+
11
+ =begin
12
+
13
+
14
+ puts 'word'
15
+
16
+ mm = MyModel.new
17
+ puts 'word2'
18
+
19
+ mcm = MyChildModel.new
20
+
21
+ puts 'mcm instance methods=' + MyChildModel.instance_methods(true).inspect
22
+ #puts 'mcm=' + mcm.instance_methods(false)
23
+ puts 'mcm class vars = ' + mcm.class.class_variables.inspect
24
+ puts mcm.class == MyChildModel
25
+ puts 'saved? ' + mm.save.to_s
26
+ puts mm.errors.inspect
27
+
28
+ puts "mm attributes=" + MyModel.defined_attributes.inspect
29
+ puts "mcm attributes=" + MyChildModel.defined_attributes.inspect
30
+
31
+ mcm2 = MyChildModel.new
32
+ puts "mcm2 attributes=" + MyChildModel.defined_attributes.inspect
33
+
34
+ =end
@@ -1,15 +1,15 @@
1
-
2
- require File.expand_path(File.dirname(__FILE__) + "/../lib/results_array")
3
-
4
- array = SimpleRecord::ResultsArray.new()
5
- #array.extend(ResultsArray)
6
-
7
- 500.times do |i|
8
- array << "_ob_" + i.to_s
9
- end
10
-
11
- array.each do |v|
12
- puts v.to_s
13
- end
14
-
1
+
2
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/results_array")
3
+
4
+ array = SimpleRecord::ResultsArray.new()
5
+ #array.extend(ResultsArray)
6
+
7
+ 500.times do |i|
8
+ array << "_ob_" + i.to_s
9
+ end
10
+
11
+ array.each do |v|
12
+ puts v.to_s
13
+ end
14
+
15
15
  puts array[10]
data/test/temp_test.rb CHANGED
@@ -1,63 +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
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
@@ -297,8 +297,4 @@ class TestSimpleRecord < Test::Unit::TestCase
297
297
 
298
298
  end
299
299
 
300
- def test_funny_names
301
- MyModel.find(:all, :order=>"order")
302
- end
303
-
304
300
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
4
+ version: 1.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-09-21 00:00:00 -07:00
14
+ date: 2009-10-12 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -54,7 +54,7 @@ requirements: []
54
54
  rubyforge_project:
55
55
  rubygems_version: 1.3.5
56
56
  signing_key:
57
- specification_version: 2
57
+ specification_version: 3
58
58
  summary: Drop in replacement for ActiveRecord to Amazon SimpleDB instead.
59
59
  test_files:
60
60
  - test/my_child_model.rb