simple_record 1.4.19 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -100,15 +100,15 @@ Querying is similar to ActiveRecord for the most part.
100
100
 
101
101
  To find all objects that match conditions returned in an Array:
102
102
 
103
- Company.find(:all, :conditions => ["created_at > ?", 10.days.ago], :order=>"name", :limit=>50)
103
+ Company.find(:all, :conditions => ["created > ?", 10.days.ago], :order=>"name", :limit=>50)
104
104
 
105
105
  To find a single object:
106
106
 
107
- Company.find(:first, :conditions => ["name = ? AND division = ? AND created_at > ?", "Appoxy", "West", 10.days.ago ])
107
+ Company.find(:first, :conditions => ["name = ? AND division = ? AND created > ?", "Appoxy", "West", 10.days.ago ])
108
108
 
109
109
  To count objects:
110
110
 
111
- Company.find(:count, :conditions => ["name = ? AND division = ? AND created_at > ?", "Appoxy", "West", 10.days.ago ])
111
+ Company.find(:count, :conditions => ["name = ? AND division = ? AND created > ?", "Appoxy", "West", 10.days.ago ])
112
112
 
113
113
  You can also the dynamic method style, for instance the line below is the same as the Company.find(:first....) line above:
114
114
 
data/lib/simple_record.rb CHANGED
@@ -37,6 +37,7 @@ require File.expand_path(File.dirname(__FILE__) + "/simple_record/errors")
37
37
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/json")
38
38
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/logging")
39
39
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/password")
40
+ require File.expand_path(File.dirname(__FILE__) + "/simple_record/rails2")
40
41
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/results_array")
41
42
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/stats")
42
43
  require File.expand_path(File.dirname(__FILE__) + "/simple_record/translations")
@@ -125,6 +126,7 @@ module SimpleRecord
125
126
  SimpleRecord::ActiveSdb.establish_connection(aws_access_key, aws_secret_key, @@options)
126
127
  if options[:connection_mode] == :per_thread
127
128
  @@auto_close_s3 = true
129
+ # todo: should we init this only when needed?
128
130
  @@s3 = Aws::S3.new(SimpleRecord.aws_access_key, SimpleRecord.aws_secret_key, {:connection_mode=>:per_thread})
129
131
  end
130
132
  end
@@ -164,6 +166,16 @@ module SimpleRecord
164
166
  include SimpleRecord::Logging
165
167
  extend SimpleRecord::Logging::ClassMethods
166
168
 
169
+ # puts 'Is ActiveModel defined? ' + defined?(ActiveModel).inspect
170
+ if defined?(ActiveModel)
171
+ extend ActiveModel::Naming
172
+ include ActiveModel::Conversion
173
+ include ActiveModel::Validations
174
+ else
175
+ attr_accessor :errors
176
+ include SimpleRecord::Rails2
177
+ end
178
+
167
179
 
168
180
  def self.extended(base)
169
181
 
@@ -185,7 +197,7 @@ module SimpleRecord
185
197
  #we have to handle the virtuals.
186
198
  Attributes.handle_virtuals(attrs)
187
199
 
188
- @errors=SimpleRecord_errors.new
200
+ # @errors=SimpleRecord_errors.new
189
201
  @dirty = {}
190
202
 
191
203
  @attributes = {} # sdb values
@@ -215,6 +227,12 @@ module SimpleRecord
215
227
  end
216
228
 
217
229
 
230
+ def persisted?
231
+ true
232
+ end
233
+
234
+
235
+
218
236
  def defined_attributes_local
219
237
  # todo: store this somewhere so it doesn't keep going through this
220
238
  ret = self.class.defined_attributes
@@ -222,7 +240,7 @@ module SimpleRecord
222
240
  end
223
241
 
224
242
 
225
- attr_accessor :errors
243
+
226
244
 
227
245
  class << self;
228
246
  attr_accessor :domain_prefix
@@ -380,43 +398,12 @@ module SimpleRecord
380
398
  return false
381
399
  end
382
400
 
383
- def valid?
384
- errors.clear
385
-
386
- # run_callbacks(:validate)
387
- validate
388
-
389
- if new_record?
390
- # run_callbacks(:validate_on_create)
391
- validate_on_create
392
- else
393
- # run_callbacks(:validate_on_update)
394
- validate_on_update
395
- end
396
-
397
- errors.empty?
398
- end
399
401
 
400
402
  def new_record?
401
403
  # todo: new_record in activesdb should align with how we're defining a new record here, ie: if id is nil
402
404
  super
403
405
  end
404
406
 
405
- def invalid?
406
- !valid?
407
- end
408
-
409
- def validate
410
- true
411
- end
412
-
413
- def validate_on_create
414
- true
415
- end
416
-
417
- def validate_on_update
418
- true
419
- end
420
407
 
421
408
  @create_domain_called = false
422
409
 
@@ -561,6 +548,19 @@ module SimpleRecord
561
548
  end
562
549
 
563
550
 
551
+ def validate
552
+ true
553
+ end
554
+
555
+ def validate_on_create
556
+ true
557
+ end
558
+
559
+ def validate_on_update
560
+ true
561
+ end
562
+
563
+
564
564
  def pre_save(options)
565
565
 
566
566
  is_create = self[:id].nil?
@@ -571,7 +571,7 @@ module SimpleRecord
571
571
 
572
572
  is_create ? validate_on_create : validate_on_update
573
573
  # puts 'AFTER VALIDATIONS, ERRORS=' + errors.inspect
574
- if (!@errors.nil? && @errors.length > 0)
574
+ if (!errors.nil? && errors.size > 0)
575
575
  # puts 'THERE ARE ERRORS, returning false'
576
576
  return false
577
577
  end
@@ -1138,7 +1138,7 @@ module SimpleRecord
1138
1138
 
1139
1139
  # This is simply a place holder so we don't keep doing gets to s3 or simpledb if already checked.
1140
1140
  class RemoteNil
1141
-
1141
+
1142
1142
  end
1143
1143
 
1144
1144
 
@@ -146,6 +146,9 @@ module SimpleRecord
146
146
  #
147
147
  # This method will also create an {association)_id method that will return the ID of the foreign object
148
148
  # without actually materializing it.
149
+ #
150
+ # options:
151
+ # :class_name=>"User" - to change the default class to use
149
152
  def belongs_to(association_id, options = {})
150
153
  arg = association_id
151
154
  arg_s = arg.to_s
@@ -0,0 +1,30 @@
1
+ # Only used if ActiveModel is not present
2
+
3
+ module SimpleRecord
4
+ module Rails2
5
+
6
+
7
+ def valid?
8
+ errors.clear
9
+
10
+ # run_callbacks(:validate)
11
+ validate
12
+
13
+ if new_record?
14
+ # run_callbacks(:validate_on_create)
15
+ validate_on_create
16
+ else
17
+ # run_callbacks(:validate_on_update)
18
+ validate_on_update
19
+ end
20
+
21
+ errors.empty?
22
+ end
23
+
24
+
25
+ def invalid?
26
+ !valid?
27
+ end
28
+
29
+ end
30
+ end
data/test/temp.rb CHANGED
@@ -41,3 +41,6 @@ p = MyModel.new
41
41
  puts 'p=' + p.inspect.to_s
42
42
  puts 'p=' + p.to_s
43
43
  puts "p=" + p.inspect
44
+
45
+ id = 123
46
+ puts 'id&&id ' + (id && id.to_s).inspect
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+ require 'active_model'
3
+ require File.join(File.dirname(__FILE__), "/../lib/simple_record")
4
+ require File.join(File.dirname(__FILE__), "./test_helpers")
5
+ require File.join(File.dirname(__FILE__), "./test_base")
6
+ require "yaml"
7
+ require 'aws'
8
+ require_relative 'my_model'
9
+ require_relative 'my_child_model'
10
+ require_relative 'model_with_enc'
11
+
12
+ # To test things related to rails 3 like ActiveModel usage.
13
+ class TestRails3 < TestBase
14
+
15
+ def test_active_model_defined
16
+
17
+ my_model = MyModel.new
18
+
19
+ assert (defined?(MyModel.model_name))
20
+
21
+
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 4
8
- - 19
9
- version: 1.4.19
7
+ - 5
8
+ - 1
9
+ version: 1.5.1
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-10-29 00:00:00 -07:00
19
+ date: 2010-11-05 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ files:
51
51
  - lib/simple_record/json.rb
52
52
  - lib/simple_record/logging.rb
53
53
  - lib/simple_record/password.rb
54
+ - lib/simple_record/rails2.rb
54
55
  - lib/simple_record/results_array.rb
55
56
  - lib/simple_record/stats.rb
56
57
  - lib/simple_record/translations.rb
@@ -73,6 +74,7 @@ files:
73
74
  - test/test_lobs.rb
74
75
  - test/test_marshalled.rb
75
76
  - test/test_pagination.rb
77
+ - test/test_rails3.rb
76
78
  - test/test_results_array.rb
77
79
  - test/test_usage.rb
78
80
  has_rdoc: true
@@ -126,5 +128,6 @@ test_files:
126
128
  - test/test_lobs.rb
127
129
  - test/test_marshalled.rb
128
130
  - test/test_pagination.rb
131
+ - test/test_rails3.rb
129
132
  - test/test_results_array.rb
130
133
  - test/test_usage.rb