simple_record 2.1.6 → 2.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.markdown ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Travis Reeder, Appoxy LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown CHANGED
@@ -395,3 +395,7 @@ thread pool across your app, but for now, it will fire up a thread per shard.
395
395
 
396
396
  Special thanks to Garrett Cox for creating Activerecord2sdb which SimpleRecord is based on:
397
397
  http://activrecord2sdb.rubyforge.org/
398
+
399
+ ## License
400
+
401
+ SimpleRecord is released under the MIT License.
@@ -633,7 +633,7 @@ module SimpleRecord
633
633
 
634
634
  # This will currently return and's, or's and betweens. Doesn't hurt anything, but could remove.
635
635
  def parse_condition_fields(conditions)
636
- return nil unless conditions && conditions.present?
636
+ return nil unless conditions && conditions.present? && conditions.is_a?(Array)
637
637
  rx = /\b(\w*)[\s|>=|<=|!=|=|>|<|like|between]/
638
638
  fields = conditions[0].scan(rx)
639
639
  # puts 'condition_fields = ' + fields.inspect
@@ -1,10 +1,10 @@
1
1
  module SimpleRecord
2
- module Attributes
2
+ module Attributes
3
3
  # For all things related to defining attributes.
4
4
 
5
5
 
6
- def self.included(base)
7
- #puts 'Callbacks included in ' + base.inspect
6
+ def self.included(base)
7
+ #puts 'Callbacks included in ' + base.inspect
8
8
  =begin
9
9
  instance_eval <<-endofeval
10
10
 
@@ -16,418 +16,418 @@ module SimpleRecord
16
16
  endofeval
17
17
  =end
18
18
 
19
- end
19
+ end
20
20
 
21
21
 
22
- module ClassMethods
22
+ module ClassMethods
23
23
 
24
24
 
25
- # Add configuration to this particular class.
26
- # :single_clob=> true/false. If true will store all clobs as a single object in s3. Default is false.
27
- def sr_config(options={})
28
- get_sr_config
29
- @sr_config.merge!(options)
30
- end
25
+ # Add configuration to this particular class.
26
+ # :single_clob=> true/false. If true will store all clobs as a single object in s3. Default is false.
27
+ def sr_config(options={})
28
+ get_sr_config
29
+ @sr_config.merge!(options)
30
+ end
31
31
 
32
- def get_sr_config
33
- @sr_config ||= {}
34
- end
32
+ def get_sr_config
33
+ @sr_config ||= {}
34
+ end
35
35
 
36
- def defined_attributes
37
- @attributes ||= {}
38
- @attributes
39
- end
36
+ def defined_attributes
37
+ @attributes ||= {}
38
+ @attributes
39
+ end
40
40
 
41
- def has_attributes(*args)
42
- has_attributes2(args)
43
- end
41
+ def has_attributes(*args)
42
+ has_attributes2(args)
43
+ end
44
44
 
45
- def has_attributes2(args, options_for_all={})
45
+ def has_attributes2(args, options_for_all={})
46
46
  # puts 'args=' + args.inspect
47
47
  # puts 'options_for_all = ' + options_for_all.inspect
48
- args.each do |arg|
49
- arg_options = {}
50
- if arg.is_a?(Hash)
51
- # then attribute may have extra options
52
- arg_options = arg
53
- arg = arg_options[:name].to_sym
54
- else
55
- arg = arg.to_sym
56
- end
57
- type = options_for_all[:type] || :string
58
- attr = Attribute.new(type, arg_options)
59
- defined_attributes[arg] = attr if defined_attributes[arg].nil?
60
-
61
- # define reader method
62
- arg_s = arg.to_s # to get rid of all the to_s calls
63
- send(:define_method, arg) do
64
- ret = get_attribute(arg)
65
- return ret
66
- end
67
-
68
- # define writer method
69
- send(:define_method, arg_s+"=") do |value|
70
- set(arg, value)
71
- end
72
-
73
- define_dirty_methods(arg_s)
74
- end
75
- end
48
+ args.each do |arg|
49
+ arg_options = {}
50
+ if arg.is_a?(Hash)
51
+ # then attribute may have extra options
52
+ arg_options = arg
53
+ arg = arg_options[:name].to_sym
54
+ else
55
+ arg = arg.to_sym
56
+ end
57
+ type = options_for_all[:type] || :string
58
+ attr = Attribute.new(type, arg_options)
59
+ defined_attributes[arg] = attr if defined_attributes[arg].nil?
60
+
61
+ # define reader method
62
+ arg_s = arg.to_s # to get rid of all the to_s calls
63
+ send(:define_method, arg) do
64
+ ret = get_attribute(arg)
65
+ return ret
66
+ end
76
67
 
77
- def define_dirty_methods(arg_s)
78
- # Now for dirty methods: http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html
79
- # define changed? method
80
- send(:define_method, arg_s + "_changed?") do
81
- @dirty.has_key?(sdb_att_name(arg_s))
82
- end
83
-
84
- # define change method
85
- send(:define_method, arg_s + "_change") do
86
- old_val = @dirty[sdb_att_name(arg_s)]
87
- [old_val, get_attribute(arg_s)]
88
- end
89
-
90
- # define was method
91
- send(:define_method, arg_s + "_was") do
92
- old_val = @dirty[sdb_att_name(arg_s)]
93
- old_val
94
- end
95
- end
68
+ # define writer method
69
+ send(:define_method, arg_s+"=") do |value|
70
+ set(arg, value)
71
+ end
96
72
 
97
- def has_strings(*args)
98
- has_attributes(*args)
99
- end
73
+ define_dirty_methods(arg_s)
74
+ end
75
+ end
100
76
 
101
- def has_ints(*args)
102
- has_attributes(*args)
103
- are_ints(*args)
104
- end
77
+ def define_dirty_methods(arg_s)
78
+ # Now for dirty methods: http://api.rubyonrails.org/classes/ActiveRecord/Dirty.html
79
+ # define changed? method
80
+ send(:define_method, arg_s + "_changed?") do
81
+ @dirty.has_key?(sdb_att_name(arg_s))
82
+ end
105
83
 
106
- def has_floats(*args)
107
- has_attributes(*args)
108
- are_floats(*args)
109
- end
84
+ # define change method
85
+ send(:define_method, arg_s + "_change") do
86
+ old_val = @dirty[sdb_att_name(arg_s)]
87
+ [old_val, get_attribute(arg_s)]
88
+ end
110
89
 
111
- def has_dates(*args)
112
- has_attributes(*args)
113
- are_dates(*args)
114
- end
90
+ # define was method
91
+ send(:define_method, arg_s + "_was") do
92
+ old_val = @dirty[sdb_att_name(arg_s)]
93
+ old_val
94
+ end
95
+ end
96
+
97
+ def has_strings(*args)
98
+ has_attributes(*args)
99
+ end
100
+
101
+ def has_ints(*args)
102
+ has_attributes(*args)
103
+ are_ints(*args)
104
+ end
105
+
106
+ def has_floats(*args)
107
+ has_attributes(*args)
108
+ are_floats(*args)
109
+ end
110
+
111
+ def has_dates(*args)
112
+ has_attributes(*args)
113
+ are_dates(*args)
114
+ end
115
+
116
+ def has_booleans(*args)
117
+ has_attributes(*args)
118
+ are_booleans(*args)
119
+ end
120
+
121
+ def are_ints(*args)
122
+ # puts 'calling are_ints: ' + args.inspect
123
+ args.each do |arg|
124
+ defined_attributes[arg.to_sym].type = :int
125
+ end
126
+ end
115
127
 
116
- def has_booleans(*args)
117
- has_attributes(*args)
118
- are_booleans(*args)
119
- end
128
+ def are_floats(*args)
129
+ # puts 'calling are_ints: ' + args.inspect
130
+ args.each do |arg|
131
+ defined_attributes[arg.to_sym].type = :float
132
+ end
133
+ end
120
134
 
121
- def are_ints(*args)
122
- # puts 'calling are_ints: ' + args.inspect
123
- args.each do |arg|
124
- defined_attributes[arg.to_sym].type = :int
125
- end
126
- end
135
+ def are_dates(*args)
136
+ args.each do |arg|
137
+ defined_attributes[arg.to_sym].type = :date
138
+ end
139
+ end
127
140
 
128
- def are_floats(*args)
129
- # puts 'calling are_ints: ' + args.inspect
130
- args.each do |arg|
131
- defined_attributes[arg.to_sym].type = :float
132
- end
133
- end
141
+ def are_booleans(*args)
142
+ args.each do |arg|
143
+ defined_attributes[arg.to_sym].type = :boolean
144
+ end
145
+ end
134
146
 
135
- def are_dates(*args)
136
- args.each do |arg|
137
- defined_attributes[arg.to_sym].type = :date
138
- end
139
- end
147
+ def has_clobs(*args)
148
+ has_attributes2(args, :type=>:clob)
140
149
 
141
- def are_booleans(*args)
142
- args.each do |arg|
143
- defined_attributes[arg.to_sym].type = :boolean
144
- end
145
- end
150
+ end
146
151
 
147
- def has_clobs(*args)
148
- has_attributes2(args, :type=>:clob)
152
+ def has_virtuals(*args)
153
+ @@virtuals = args
154
+ args.each do |arg|
155
+ #we just create the accessor functions here, the actual instance variable is created during initialize
156
+ attr_accessor(arg)
157
+ end
158
+ end
159
+
160
+ # One belongs_to association per call. Call multiple times if there are more than one.
161
+ #
162
+ # This method will also create an {association)_id method that will return the ID of the foreign object
163
+ # without actually materializing it.
164
+ #
165
+ # options:
166
+ # :class_name=>"User" - to change the default class to use
167
+ def belongs_to(association_id, options = {})
168
+ arg = association_id
169
+ arg_s = arg.to_s
170
+ arg_id = arg.to_s + '_id'
171
+ attribute = Attribute.new(:belongs_to, options)
172
+ defined_attributes[arg] = attribute
173
+
174
+ # todo: should also handle foreign_key http://74.125.95.132/search?q=cache:KqLkxuXiBBQJ:wiki.rubyonrails.org/rails/show/belongs_to+rails+belongs_to&hl=en&ct=clnk&cd=1&gl=us
175
+ # puts "arg_id=#{arg}_id"
176
+ # puts "is defined? " + eval("(defined? #{arg}_id)").to_s
177
+ # puts 'atts=' + @attributes.inspect
178
+
179
+ # Define reader method
180
+ send(:define_method, arg) do
181
+ return get_attribute(arg)
182
+ end
149
183
 
150
- end
151
184
 
152
- def has_virtuals(*args)
153
- @@virtuals = args
154
- args.each do |arg|
155
- #we just create the accessor functions here, the actual instance variable is created during initialize
156
- attr_accessor(arg)
157
- end
158
- end
185
+ # Define writer method
186
+ send(:define_method, arg.to_s + "=") do |value|
187
+ set(arg, value)
188
+ end
159
189
 
160
- # One belongs_to association per call. Call multiple times if there are more than one.
161
- #
162
- # This method will also create an {association)_id method that will return the ID of the foreign object
163
- # without actually materializing it.
164
- #
165
- # options:
166
- # :class_name=>"User" - to change the default class to use
167
- def belongs_to(association_id, options = {})
168
- arg = association_id
169
- arg_s = arg.to_s
170
- arg_id = arg.to_s + '_id'
171
- attribute = Attribute.new(:belongs_to, options)
172
- defined_attributes[arg] = attribute
173
-
174
- # todo: should also handle foreign_key http://74.125.95.132/search?q=cache:KqLkxuXiBBQJ:wiki.rubyonrails.org/rails/show/belongs_to+rails+belongs_to&hl=en&ct=clnk&cd=1&gl=us
175
- # puts "arg_id=#{arg}_id"
176
- # puts "is defined? " + eval("(defined? #{arg}_id)").to_s
177
- # puts 'atts=' + @attributes.inspect
178
-
179
- # Define reader method
180
- send(:define_method, arg) do
181
- return get_attribute(arg)
182
- end
183
-
184
-
185
- # Define writer method
186
- send(:define_method, arg.to_s + "=") do |value|
187
- set(arg, value)
188
- end
189
-
190
-
191
- # Define ID reader method for reading the associated objects id without getting the entire object
192
- send(:define_method, arg_id) do
193
- get_attribute_sdb(arg_s)
194
- end
195
-
196
- # Define writer method for setting the _id directly without the associated object
197
- send(:define_method, arg_id + "=") do |value|
190
+
191
+ # Define ID reader method for reading the associated objects id without getting the entire object
192
+ send(:define_method, arg_id) do
193
+ get_attribute_sdb(arg_s)
194
+ end
195
+
196
+ # Define writer method for setting the _id directly without the associated object
197
+ send(:define_method, arg_id + "=") do |value|
198
198
  # rb_att_name = arg_s # n2 = name.to_s[0, name.length-3]
199
- set(arg_id, value)
199
+ set(arg_id, value)
200
200
  # if value.nil?
201
201
  # self[arg_id] = nil unless self[arg_id].nil? # if it went from something to nil, then we have to remember and remove attribute on save
202
202
  # else
203
203
  # self[arg_id] = value
204
204
  # end
205
- end
206
-
207
- send(:define_method, "create_"+arg.to_s) do |*params|
208
- newsubrecord=eval(arg.to_s.classify).new(*params)
209
- newsubrecord.save
210
- arg_id = arg.to_s + '_id'
211
- self[arg_id]=newsubrecord.id
212
- end
205
+ end
213
206
 
214
- define_dirty_methods(arg_s)
215
- end
207
+ send(:define_method, "create_"+arg.to_s) do |*params|
208
+ newsubrecord=eval(arg.to_s.classify).new(*params)
209
+ newsubrecord.save
210
+ arg_id = arg.to_s + '_id'
211
+ self[arg_id]=newsubrecord.id
212
+ end
216
213
 
217
- def has_many(*args)
218
- args.each do |arg|
219
- #okay, this creates an instance method with the pluralized name of the symbol passed to belongs_to
220
- send(:define_method, arg) do
221
- #when called, the method creates a new, very temporary instance of the Activerecordtosdb_subrecord class
222
- #It is passed the three initializers it needs:
223
- #note the first parameter is just a string by time new gets it, like "user"
224
- #the second and third parameters are still a variable when new gets it, like user_id
225
- return eval(%{Activerecordtosdb_subrecord_array.new('#{arg}', self.class.name ,id)})
226
- end
227
- end
228
- #Disclaimer: this whole funciton just seems crazy to me, and a bit inefficient. But it was the clearest way I could think to do it code wise.
229
- #It's bad programming form (imo) to have a class method require something that isn't passed to it through it's variables.
230
- #I couldn't pass the id when calling find, since the original find doesn't work that way, so I was left with this.
231
- end
214
+ define_dirty_methods(arg_s)
215
+ end
216
+
217
+ def has_many(*args)
218
+ args.each do |arg|
219
+ #okay, this creates an instance method with the pluralized name of the symbol passed to belongs_to
220
+ send(:define_method, arg) do
221
+ #when called, the method creates a new, very temporary instance of the Activerecordtosdb_subrecord class
222
+ #It is passed the three initializers it needs:
223
+ #note the first parameter is just a string by time new gets it, like "user"
224
+ #the second and third parameters are still a variable when new gets it, like user_id
225
+ return eval(%{Activerecordtosdb_subrecord_array.new('#{arg}', self.class.name ,id)})
226
+ end
227
+ end
228
+ #Disclaimer: this whole funciton just seems crazy to me, and a bit inefficient. But it was the clearest way I could think to do it code wise.
229
+ #It's bad programming form (imo) to have a class method require something that isn't passed to it through it's variables.
230
+ #I couldn't pass the id when calling find, since the original find doesn't work that way, so I was left with this.
231
+ end
232
232
 
233
- def has_one(*args)
233
+ def has_one(*args)
234
234
 
235
- end
235
+ end
236
236
 
237
237
 
238
- end
238
+ end
239
239
 
240
- @@virtuals=[]
240
+ @@virtuals=[]
241
241
 
242
- def self.handle_virtuals(attrs)
243
- @@virtuals.each do |virtual|
244
- #we first copy the information for the virtual to an instance variable of the same name
245
- eval("@#{virtual}=attrs['#{virtual}']")
246
- #and then remove the parameter before it is passed to initialize, so that it is NOT sent to SimpleDB
247
- eval("attrs.delete('#{virtual}')")
248
- end
249
- end
242
+ def self.handle_virtuals(attrs)
243
+ @@virtuals.each do |virtual|
244
+ #we first copy the information for the virtual to an instance variable of the same name
245
+ eval("@#{virtual}=attrs['#{virtual}']")
246
+ #and then remove the parameter before it is passed to initialize, so that it is NOT sent to SimpleDB
247
+ eval("attrs.delete('#{virtual}')")
248
+ end
249
+ end
250
250
 
251
251
 
252
- def set(name, value, dirtify=true)
252
+ def set(name, value, dirtify=true)
253
253
  # puts "SET #{name}=#{value.inspect}" if SimpleRecord.logging?
254
254
  # puts "self=" + self.inspect
255
- attname = name.to_s # default attname
256
- name = name.to_sym
257
- att_meta = get_att_meta(name)
258
- store_rb_val = false
259
- if att_meta.nil?
260
- # check if it ends with id and see if att_meta is there
261
- ends_with = name.to_s[-3, 3]
262
- if ends_with == "_id"
255
+ attname = name.to_s # default attname
256
+ name = name.to_sym
257
+ att_meta = get_att_meta(name)
258
+ store_rb_val = false
259
+ if att_meta.nil?
260
+ # check if it ends with id and see if att_meta is there
261
+ ends_with = name.to_s[-3, 3]
262
+ if ends_with == "_id"
263
263
  # puts 'ends with id'
264
- n2 = name.to_s[0, name.length-3]
264
+ n2 = name.to_s[0, name.length-3]
265
265
  # puts 'n2=' + n2
266
- att_meta = defined_attributes_local[n2.to_sym]
266
+ att_meta = defined_attributes_local[n2.to_sym]
267
267
  # puts 'defined_attributes_local=' + defined_attributes_local.inspect
268
- attname = name.to_s
269
- attvalue = value
270
- name = n2.to_sym
271
- end
272
- return if att_meta.nil?
273
- else
274
- if att_meta.type == :belongs_to
275
- ends_with = name.to_s[-3, 3]
276
- if ends_with == "_id"
277
- att_name = name.to_s
278
- attvalue = value
279
- else
280
- attname = name.to_s + '_id'
281
- attvalue = value.nil? ? nil : value.id
282
- store_rb_val = true
283
- end
284
- elsif att_meta.type == :clob
285
- make_dirty(name, value) if dirtify
286
- @lobs[name] = value
287
- return
288
- else
289
- attname = name.to_s
290
- attvalue = att_meta.init_value(value)
268
+ attname = name.to_s
269
+ attvalue = value
270
+ name = n2.to_sym
271
+ end
272
+ return if att_meta.nil?
273
+ else
274
+ if att_meta.type == :belongs_to
275
+ ends_with = name.to_s[-3, 3]
276
+ if ends_with == "_id"
277
+ att_name = name.to_s
278
+ attvalue = value
279
+ else
280
+ attname = name.to_s + '_id'
281
+ attvalue = value.nil? ? nil : value.id
282
+ store_rb_val = true
283
+ end
284
+ elsif att_meta.type == :clob
285
+ make_dirty(name, value) if dirtify
286
+ @lobs[name] = value
287
+ return
288
+ else
289
+ attname = name.to_s
290
+ attvalue = att_meta.init_value(value)
291
291
  # attvalue = value
292
- #puts 'converted ' + value.inspect + ' to ' + attvalue.inspect
293
- end
294
- end
295
- attvalue = strip_array(attvalue)
296
- make_dirty(name, attvalue) if dirtify
292
+ #puts 'converted ' + value.inspect + ' to ' + attvalue.inspect
293
+ end
294
+ end
295
+ attvalue = strip_array(attvalue)
296
+ make_dirty(name, attvalue) if dirtify
297
297
  # puts "ARG=#{attname.to_s} setting to #{attvalue}"
298
- sdb_val = ruby_to_sdb(name, attvalue)
298
+ sdb_val = ruby_to_sdb(name, attvalue)
299
299
  # puts "sdb_val=" + sdb_val.to_s
300
- @attributes[attname] = sdb_val
300
+ @attributes[attname] = sdb_val
301
301
  # attvalue = wrap_if_required(name, attvalue, sdb_val)
302
302
  # puts 'attvalue2=' + attvalue.to_s
303
303
 
304
- if store_rb_val
305
- @attributes_rb[name.to_s] = value
306
- else
307
- @attributes_rb.delete(name.to_s)
308
- end
304
+ if store_rb_val
305
+ @attributes_rb[name.to_s] = value
306
+ else
307
+ @attributes_rb.delete(name.to_s)
308
+ end
309
309
 
310
- end
310
+ end
311
311
 
312
312
 
313
- def set_attribute_sdb(name, val)
314
- @attributes[sdb_att_name(name)] = val
315
- end
313
+ def set_attribute_sdb(name, val)
314
+ @attributes[sdb_att_name(name)] = val
315
+ end
316
316
 
317
317
 
318
- def get_attribute_sdb(name)
319
- name = name.to_sym
320
- ret = strip_array(@attributes[sdb_att_name(name)])
321
- return ret
322
- end
318
+ def get_attribute_sdb(name)
319
+ name = name.to_sym
320
+ ret = strip_array(@attributes[sdb_att_name(name)])
321
+ return ret
322
+ end
323
323
 
324
- # Since SimpleDB supports multiple attributes per value, the values are an array.
325
- # This method will return the value unwrapped if it's the only, otherwise it will return the array.
326
- def get_attribute(name)
324
+ # Since SimpleDB supports multiple attributes per value, the values are an array.
325
+ # This method will return the value unwrapped if it's the only, otherwise it will return the array.
326
+ def get_attribute(name)
327
327
  # puts "get_attribute #{name}"
328
- # Check if this arg is already converted
329
- name_s = name.to_s
330
- name = name.to_sym
331
- att_meta = get_att_meta(name)
328
+ # Check if this arg is already converted
329
+ name_s = name.to_s
330
+ name = name.to_sym
331
+ att_meta = get_att_meta(name)
332
332
  # puts "att_meta for #{name}: " + att_meta.inspect
333
- if att_meta && att_meta.type == :clob
334
- ret = @lobs[name]
333
+ if att_meta && att_meta.type == :clob
334
+ ret = @lobs[name]
335
335
  # puts 'get_attribute clob ' + ret.inspect
336
- if ret
337
- if ret.is_a? RemoteNil
338
- return nil
339
- else
340
- return ret
341
- end
342
- end
343
- # get it from s3
344
- unless new_record?
345
- if self.class.get_sr_config[:single_clob]
346
- begin
347
- single_clob = s3_bucket(false, :s3_bucket=>:new).get(single_clob_id)
348
- single_clob = JSON.parse(single_clob)
336
+ if ret
337
+ if ret.is_a? RemoteNil
338
+ return nil
339
+ else
340
+ return ret
341
+ end
342
+ end
343
+ # get it from s3
344
+ unless new_record?
345
+ if self.class.get_sr_config[:single_clob]
346
+ begin
347
+ single_clob = s3_bucket(false, :s3_bucket=>:new).get(single_clob_id)
348
+ single_clob = JSON.parse(single_clob)
349
349
  # puts "single_clob=" + single_clob.inspect
350
- single_clob.each_pair do |name2,val|
351
- @lobs[name2.to_sym] = val
352
- end
353
- ret = @lobs[name]
354
- SimpleRecord.stats.s3_gets += 1
355
- rescue Aws::AwsError => ex
356
- if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/)
357
- ret = nil
358
- else
359
- raise ex
360
- end
361
- end
362
- else
363
- begin
364
- ret = s3_bucket.get(s3_lob_id(name))
350
+ single_clob.each_pair do |name2, val|
351
+ @lobs[name2.to_sym] = val
352
+ end
353
+ ret = @lobs[name]
354
+ SimpleRecord.stats.s3_gets += 1
355
+ rescue Aws::AwsError => ex
356
+ if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/)
357
+ ret = nil
358
+ else
359
+ raise ex
360
+ end
361
+ end
362
+ else
363
+ begin
364
+ ret = s3_bucket.get(s3_lob_id(name))
365
365
  # puts 'got from s3 ' + ret.inspect
366
- SimpleRecord.stats.s3_gets += 1
367
- rescue Aws::AwsError => ex
368
- if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/)
369
- ret = nil
370
- else
371
- raise ex
372
- end
373
- end
374
- end
375
-
376
- if ret.nil?
377
- ret = RemoteNil.new
378
- end
379
- end
380
- @lobs[name] = ret
381
- return nil if ret.is_a? RemoteNil
382
- return ret
383
- else
384
- @attributes_rb = {} unless @attributes_rb # was getting errors after upgrade.
385
- ret = @attributes_rb[name_s] # instance_variable_get(instance_var)
386
- return ret unless ret.nil?
387
- return nil if ret.is_a? RemoteNil
388
- ret = get_attribute_sdb(name)
389
- # p ret
390
- ret = sdb_to_ruby(name, ret)
391
- # p ret
392
- @attributes_rb[name_s] = ret
393
- return ret
366
+ SimpleRecord.stats.s3_gets += 1
367
+ rescue Aws::AwsError => ex
368
+ if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/)
369
+ ret = nil
370
+ else
371
+ raise ex
372
+ end
394
373
  end
374
+ end
395
375
 
376
+ if ret.nil?
377
+ ret = RemoteNil.new
378
+ end
396
379
  end
380
+ @lobs[name] = ret
381
+ return nil if ret.is_a? RemoteNil
382
+ return ret
383
+ else
384
+ @attributes_rb = {} unless @attributes_rb # was getting errors after upgrade.
385
+ ret = @attributes_rb[name_s] # instance_variable_get(instance_var)
386
+ return ret unless ret.nil?
387
+ return nil if ret.is_a? RemoteNil
388
+ ret = get_attribute_sdb(name)
389
+ # p ret
390
+ ret = sdb_to_ruby(name, ret)
391
+ # p ret
392
+ @attributes_rb[name_s] = ret
393
+ return ret
394
+ end
397
395
 
396
+ end
398
397
 
399
- private
400
- def set_attributes(atts)
401
- atts.each_pair do |k, v|
402
- set(k, v)
403
- end
404
- end
405
398
 
399
+ private
400
+ def set_attributes(atts)
401
+ atts.each_pair do |k, v|
402
+ set(k, v)
403
+ end
404
+ end
406
405
 
407
- # Holds information about an attribute
408
- class Attribute
409
- attr_accessor :type, :options
410
406
 
411
- def initialize(type, options=nil)
412
- @type = type
413
- @options = options
414
- end
407
+ # Holds information about an attribute
408
+ class Attribute
409
+ attr_accessor :type, :options
415
410
 
416
- def init_value(value)
417
- return value if value.nil?
418
- ret = value
419
- case self.type
420
- when :int
421
- if value.is_a? Array
422
- ret = value.collect { |x| x.to_i }
423
- else
424
- ret = value.to_i
425
- end
426
- end
427
- ret
428
- end
411
+ def initialize(type, options=nil)
412
+ @type = type
413
+ @options = options
414
+ end
429
415
 
416
+ def init_value(value)
417
+ return value if value.nil?
418
+ ret = value
419
+ case self.type
420
+ when :int
421
+ if value.is_a? Array
422
+ ret = value.collect { |x| x.to_i }
423
+ else
424
+ ret = value.to_i
425
+ end
430
426
  end
427
+ ret
428
+ end
431
429
 
432
430
  end
431
+
432
+ end
433
433
  end
@@ -31,7 +31,7 @@ module SimpleRecord
31
31
  result = {
32
32
  'id' => self.id
33
33
  }
34
- result['json_class'] = self.class.name unless options[:exclude_json_class]
34
+ result['json_class'] = self.class.name unless options && options[:exclude_json_class]
35
35
  defined_attributes_local.each_pair do |name, val|
36
36
  # puts name.to_s + "=" + val.inspect
37
37
  if val.type == :belongs_to
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_record
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.6
5
+ version: 2.1.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Reeder
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-05-08 00:00:00 Z
15
+ date: 2011-06-10 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: aws
@@ -43,6 +43,7 @@ executables: []
43
43
  extensions: []
44
44
 
45
45
  extra_rdoc_files:
46
+ - LICENSE.markdown
46
47
  - README.markdown
47
48
  files:
48
49
  - lib/simple_record.rb
@@ -59,6 +60,7 @@ files:
59
60
  - lib/simple_record/stats.rb
60
61
  - lib/simple_record/translations.rb
61
62
  - lib/simple_record/validations.rb
63
+ - LICENSE.markdown
62
64
  - README.markdown
63
65
  homepage: http://github.com/appoxy/simple_record/
64
66
  licenses: []
@@ -73,6 +75,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
75
  requirements:
74
76
  - - ">="
75
77
  - !ruby/object:Gem::Version
78
+ hash: 4074993841537630187
79
+ segments:
80
+ - 0
76
81
  version: "0"
77
82
  required_rubygems_version: !ruby/object:Gem::Requirement
78
83
  none: false