simple_record 1.4.13 → 1.4.15

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -193,7 +193,8 @@ values should be stored in S3. Fortunately SimpleRecord takes care of this for y
193
193
  string value.
194
194
 
195
195
  has_clobs :my_clob
196
-
196
+
197
+ These clob values will be stored in s3 under a bucket named: "#{aws_access_key}_lobs"
197
198
 
198
199
  ## Tips and Tricks and Things to Know
199
200
 
@@ -95,6 +95,7 @@ module SimpleRecord
95
95
  params_for_count[0] = :count
96
96
  params_for_count[1] = params_for_count[1].dup # for deep clone
97
97
  params_for_count[1].delete(:limit)
98
+ params_for_count[1].delete(:per_token)
98
99
 
99
100
  # puts '@params2=' + @params.inspect
100
101
  # puts 'params_for_count=' + params_for_count.inspect
@@ -117,7 +118,12 @@ module SimpleRecord
117
118
  limit = options[:limit]
118
119
  # puts 'limit=' + limit.inspect
119
120
 
120
- @items[i..@items.size].each do |v|
121
+ if i > @items.size
122
+ i = @items.size
123
+ end
124
+ range = i..@items.size
125
+ # puts 'range=' + range.inspect
126
+ @items[range].each do |v|
121
127
  # puts "i=" + i.to_s
122
128
  yield v
123
129
  i += 1
data/lib/simple_record.rb CHANGED
@@ -47,6 +47,8 @@ module SimpleRecord
47
47
  @@options = {}
48
48
  @@stats = SimpleRecord::Stats.new
49
49
  @@logging = false
50
+ @@s3 = nil
51
+ @@auto_close_s3 = false
50
52
 
51
53
  class << self;
52
54
  attr_accessor :aws_access_key, :aws_secret_key
@@ -105,16 +107,35 @@ module SimpleRecord
105
107
  # :per_thread (one connection per thread)
106
108
  # :pool (uses a connection pool with a maximum number of connections - NOT IMPLEMENTED YET)
107
109
  # :logger => Logger Object # Logger instance: logs to STDOUT if omitted
108
- def establish_connection(aws_access_key=nil, aws_secret_key=nil, params={})
110
+ def establish_connection(aws_access_key=nil, aws_secret_key=nil, options={})
109
111
  @aws_access_key = aws_access_key
110
112
  @aws_secret_key = aws_secret_key
111
- @@options.merge!(params)
113
+ @@options.merge!(options)
112
114
  #puts 'SimpleRecord.establish_connection with options: ' + @@options.inspect
113
115
  SimpleRecord::ActiveSdb.establish_connection(aws_access_key, aws_secret_key, @@options)
116
+ if options[:connection_mode] == :per_thread
117
+ @@auto_close_s3 = true
118
+ @@s3 = Aws::S3.new(SimpleRecord.aws_access_key, SimpleRecord.aws_secret_key, {:connection_mode=>:per_thread})
119
+ end
114
120
  end
115
121
 
122
+ # Call this to close the connection to SimpleDB.
123
+ # If you're using this in Rails with per_thread connection mode, you should do this in
124
+ # an after_filter for each request.
116
125
  def close_connection()
117
126
  SimpleRecord::ActiveSdb.close_connection
127
+ @@s3.close_connection if @@auto_close_s3
128
+ end
129
+
130
+ # If you'd like to specify the s3 connection to use for LOBs, you can pass it in here.
131
+ # We recommend that this connection matches the type of connection you're using for SimpleDB,
132
+ # at least if you're using per_thread connection mode.
133
+ def s3=(s3)
134
+ @@s3 = s3
135
+ end
136
+
137
+ def s3
138
+ @@s3
118
139
  end
119
140
 
120
141
  def options
@@ -488,6 +509,10 @@ module SimpleRecord
488
509
  end
489
510
 
490
511
  def s3
512
+
513
+ return SimpleRecord.s3 if SimpleRecord.s3
514
+ # todo: should optimize this somehow, like use the same connection_mode as used in SR
515
+ # or keep open while looping in ResultsArray.
491
516
  Aws::S3.new(SimpleRecord.aws_access_key, SimpleRecord.aws_secret_key)
492
517
  end
493
518
 
@@ -11,7 +11,7 @@ require_relative 'model_with_enc'
11
11
  # Tests for SimpleRecord
12
12
  #
13
13
 
14
- class TestSimpleRecord < TestBase
14
+ class SimpleRecordTest < TestBase
15
15
 
16
16
 
17
17
  def test_save_get
@@ -26,8 +26,8 @@ class TestSimpleRecord < TestBase
26
26
  assert !mm.updated.nil?
27
27
  assert !mm.id.nil?
28
28
  assert mm.age == 32
29
- assert mm.cool = true
30
- assert mm.name = "Travis"
29
+ assert mm.cool == true
30
+ assert mm.name == "Travis"
31
31
 
32
32
  id = mm.id
33
33
  puts 'id=' + id.to_s
@@ -39,8 +39,8 @@ class TestSimpleRecord < TestBase
39
39
  assert mm2.age == mm.age
40
40
  assert mm2.cool == mm.cool
41
41
  assert mm2.age == 32
42
- assert mm2.cool = true
43
- assert mm2.name = "Travis"
42
+ assert mm2.cool == true
43
+ assert mm2.name == "Travis"
44
44
  assert mm2.created.is_a? DateTime
45
45
 
46
46
  # test nilification
@@ -177,8 +177,8 @@ class TestSimpleRecord < TestBase
177
177
  assert mm.nickname == mm.name
178
178
 
179
179
  mm2 = MyModel.find(mm.id)
180
- assert mm2.nickname = mm.nickname
181
- assert mm2.name = mm.name
180
+ assert_equal mm2.nickname, mm.nickname
181
+ assert_equal mm2.name, mm.name
182
182
 
183
183
 
184
184
  end
@@ -262,7 +262,7 @@ class TestSimpleRecord < TestBase
262
262
  assert mmc3.my_model_id == mm2.id
263
263
  assert mmc3.changed?
264
264
  assert mmc3.my_model_changed?
265
- assert mmc3.my_model.id = mm2.id
265
+ assert mmc3.my_model.id == mm2.id
266
266
 
267
267
  end
268
268
 
@@ -541,7 +541,7 @@ class TestSimpleRecord < TestBase
541
541
  def test_atts_using_strings_and_symbols
542
542
  mm = MyModel.new({:name=>"myname"})
543
543
  mm2 = MyModel.new({"name"=>"myname"})
544
- assert mm.name = mm2.name
544
+ assert_equal(mm.name, mm2.name)
545
545
 
546
546
  mm.save
547
547
  mm2.save
@@ -549,7 +549,7 @@ class TestSimpleRecord < TestBase
549
549
 
550
550
  mm = MyModel.find(mm.id)
551
551
  mm2 = MyModel.find(mm2.id)
552
- assert mm.name = mm2.name
552
+ assert_equal mm.name, mm2.name
553
553
  end
554
554
 
555
555
  def test_constructor_using_belongs_to_ids
@@ -559,10 +559,17 @@ class TestSimpleRecord < TestBase
559
559
 
560
560
  mm2 = MyChildModel.new({"name"=>"myname2", :my_model_id=>mm.id})
561
561
  puts 'mm2=' + mm2.inspect
562
- assert mm.id == mm2.my_model_id, "#{mm.id} != #{mm2.my_model_id}"
562
+ assert_equal mm.id, mm2.my_model_id, "#{mm.id} != #{mm2.my_model_id}"
563
563
  mm3 = mm2.my_model
564
564
  puts 'mm3=' + mm3.inspect
565
- assert mm.name == mm3.name
565
+ assert_equal mm.name, mm3.name
566
+
567
+ mm3 = MyChildModel.create(:my_model_id=>mm.id, :name=>"myname3")
568
+
569
+ sleep 2
570
+ mm4 = MyChildModel.find(mm3.id)
571
+ assert_equal mm4.my_model_id, mm.id
572
+ assert !mm4.my_model.nil?
566
573
 
567
574
  end
568
575
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 13
9
- version: 1.4.13
8
+ - 15
9
+ version: 1.4.15
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Reeder
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-23 00:00:00 -07:00
19
+ date: 2010-10-19 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,7 @@ files:
61
61
  - test/my_child_model.rb
62
62
  - test/my_model.rb
63
63
  - test/paging_array_test.rb
64
+ - test/simple_record_test.rb
64
65
  - test/temp.rb
65
66
  - test/temp_test.rb
66
67
  - test/test_base.rb
@@ -73,7 +74,6 @@ files:
73
74
  - test/test_marshalled.rb
74
75
  - test/test_pagination.rb
75
76
  - test/test_results_array.rb
76
- - test/test_simple_record.rb
77
77
  - test/test_usage.rb
78
78
  has_rdoc: true
79
79
  homepage: http://github.com/appoxy/simple_record/
@@ -114,6 +114,7 @@ test_files:
114
114
  - test/my_child_model.rb
115
115
  - test/my_model.rb
116
116
  - test/paging_array_test.rb
117
+ - test/simple_record_test.rb
117
118
  - test/temp.rb
118
119
  - test/temp_test.rb
119
120
  - test/test_base.rb
@@ -126,5 +127,4 @@ test_files:
126
127
  - test/test_marshalled.rb
127
128
  - test/test_pagination.rb
128
129
  - test/test_results_array.rb
129
- - test/test_simple_record.rb
130
130
  - test/test_usage.rb