Method: SimpleRecord::Attributes#get_attribute
- Defined in:
- lib/simple_record/attributes.rb
#get_attribute(name) ⇒ Object
Since SimpleDB supports multiple attributes per value, the values are an array. This method will return the value unwrapped if it’s the only, otherwise it will return the array.
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/simple_record/attributes.rb', line 326 def get_attribute(name) # puts "get_attribute #{name}" # Check if this arg is already converted name_s = name.to_s name = name.to_sym = (name) # puts "att_meta for #{name}: " + att_meta.inspect if && .type == :clob ret = @lobs[name] # puts 'get_attribute clob ' + ret.inspect if ret if ret.is_a? RemoteNil return nil else return ret end end # get it from s3 unless new_record? if self.class.get_sr_config[:single_clob] begin single_clob = s3_bucket(false, :s3_bucket=>:new).get(single_clob_id) single_clob = JSON.parse(single_clob) # puts "single_clob=" + single_clob.inspect single_clob.each_pair do |name2,val| @lobs[name2.to_sym] = val end ret = @lobs[name] SimpleRecord.stats.s3_gets += 1 rescue Aws::AwsError => ex if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/) ret = nil else raise ex end end else begin ret = s3_bucket.get(s3_lob_id(name)) # puts 'got from s3 ' + ret.inspect SimpleRecord.stats.s3_gets += 1 rescue Aws::AwsError => ex if ex.include?(/NoSuchKey/) || ex.include?(/NoSuchBucket/) ret = nil else raise ex end end end if ret.nil? ret = RemoteNil.new end end @lobs[name] = ret return nil if ret.is_a? RemoteNil return ret else @attributes_rb = {} unless @attributes_rb # was getting errors after upgrade. ret = @attributes_rb[name_s] # instance_variable_get(instance_var) return ret unless ret.nil? return nil if ret.is_a? RemoteNil ret = get_attribute_sdb(name) # p ret ret = sdb_to_ruby(name, ret) # p ret @attributes_rb[name_s] = ret return ret end end |