Class: SimpleRecord::Base

Inherits:
Aws::ActiveSdb::Base
  • Object
show all
Extended by:
Attributes
Includes:
Callbacks, Translations
Defined in:
lib/simple_record.rb

Constant Summary collapse

@@cache_store =
nil
@@regex_no_id =
/.*Couldn't find.*with ID.*/
@@debug =
""

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

are_booleans, are_dates, are_ints, belongs_to, define_dirty_methods, defined_attributes, handle_virtuals, has_attributes, has_booleans, has_dates, has_ints, has_many, has_one, has_strings, has_virtuals, included

Methods included from Callbacks

#after_destroy, #before_destroy, included, setup_callbacks

Methods included from Translations

#convert_dates_to_sdb, decrypt, encrypt, pad_and_offset, #pad_and_offset_ints_to_sdb, pass_hash, pass_hash_check, #ruby_to_sdb, #sdb_to_ruby, #to_bool, #to_date, un_offset_int, #unpad, #unpad_self, #wrap_if_required

Constructor Details

#initialize(attrs = {}) ⇒ Base



108
109
110
111
112
113
114
115
116
117
# File 'lib/simple_record.rb', line 108

def initialize(attrs={})
    # 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

    initialize_base(attrs)

    # Convert attributes to sdb values
    attrs.each_pair do |name, value|
        set(name, value, true)
    end
end

Class Attribute Details

.domain_prefixObject

Returns the value of attribute domain_prefix.



163
164
165
# File 'lib/simple_record.rb', line 163

def domain_prefix
  @domain_prefix
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



160
161
162
# File 'lib/simple_record.rb', line 160

def errors
  @errors
end

Class Method Details

.all(*args) ⇒ Object



708
709
710
# File 'lib/simple_record.rb', line 708

def self.all(*args)
    find(:all, *args)
end

.batch_save(objects, options = {}) ⇒ Object

Run pre_save on each object, then runs batch_put_attributes Returns



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/simple_record.rb', line 473

def self.batch_save(objects, options={})
    results = []
    to_save = []
    if objects && objects.size > 0
        objects.each do |o|
            ok = o.pre_save(options)
            raise "Pre save failed on object [" + o.inspect + "]" if !ok
            results << ok
            next if !ok # todo: this shouldn't be here should it?  raises above
            o.pre_save2
            to_save << Aws::SdbInterface::Item.new(o.id, o.attributes, true)
            if to_save.size == 25 # Max amount SDB will accept
                connection.batch_put_attributes(domain, to_save)
                to_save.clear
            end
        end
    end
    connection.batch_put_attributes(domain, to_save) if to_save.size > 0
    results
end

.cache_key(class_name, id) ⇒ Object



778
779
780
# File 'lib/simple_record.rb', line 778

def self.cache_key(class_name, id)
    return class_name + "/" + id.to_s
end

.cache_results(results) ⇒ Object



764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/simple_record.rb', line 764

def self.cache_results(results)
    if !cache_store.nil? && !results.nil?
        if results.is_a?(Array)
            # todo: cache each result
        else
            class_name = results.class.name
            id = results.id
            cache_key = self.cache_key(class_name, id)
            #puts 'caching result at ' + cache_key + ': ' + results.inspect
            cache_store.write(cache_key, results, :expires_in =>30)
        end
    end
end

.cache_storeObject



174
175
176
# File 'lib/simple_record.rb', line 174

def self.cache_store
    return @@cache_store
end

.cache_store=(cache) ⇒ Object

Set the cache to use



170
171
172
# File 'lib/simple_record.rb', line 170

def self.cache_store=(cache)
    @@cache_store = cache
end

.convert_condition_params(options) ⇒ Object



752
753
754
755
756
757
758
759
760
761
762
# File 'lib/simple_record.rb', line 752

def self.convert_condition_params(options)
    return if options.nil?
    conditions = options[:conditions]
    if !conditions.nil? && conditions.size > 1
        # all after first are values
        conditions.collect! { |x|
            Translations.pad_and_offset(x)
        }
    end

end

.count(*args) ⇒ Object



716
717
718
# File 'lib/simple_record.rb', line 716

def self.count(*args)
    find(:count, *args)
end

.create(attributes = {}) ⇒ Object



645
646
647
648
# File 'lib/simple_record.rb', line 645

def self.create(attributes={})
#            puts "About to create in domain #{domain}"
    super
end

.debugObject



784
785
786
# File 'lib/simple_record.rb', line 784

def self.debug
    @@debug
end

.delete(id) ⇒ Object

Usage: ClassName.delete id



497
498
499
# File 'lib/simple_record.rb', line 497

def self.delete(id)
    connection.delete_attributes(domain, id)
end

.delete_all(*params) ⇒ Object



501
502
503
504
505
506
507
508
509
510
# File 'lib/simple_record.rb', line 501

def self.delete_all(*params)
    # could make this quicker by just getting item_names and deleting attributes rather than creating objects
    obs = self.find(params)
    i = 0
    obs.each do |a|
        a.delete
        i+=1
    end
    return i
end

.destroy_all(*params) ⇒ Object



512
513
514
515
516
517
518
519
520
# File 'lib/simple_record.rb', line 512

def self.destroy_all(*params)
    obs = self.find(params)
    i = 0
    obs.each do |a|
        a.destroy
        i+=1
    end
    return i
end

.domainObject



201
202
203
204
205
206
207
208
# File 'lib/simple_record.rb', line 201

def self.domain
    #return self.get_domain_name unless self.get_domain_name.nil?
    d = super
#            puts 'in self.domain, d=' + d.to_s + ' domain_prefix=' + SimpleRecord::Base.domain_prefix.to_s
    domain_name_for_class = (SimpleRecord::Base.domain_prefix || "") + d.to_s
    #self.set_domain_name(domain_name_for_class)
    domain_name_for_class
end

.find(*params) ⇒ Object

Usage: Find by ID:

MyModel.find(ID)

Query example:

MyModel.find(:all, :conditions=>["name = ?", name], :order=>"created desc", :limit=>10)


660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/simple_record.rb', line 660

def self.find(*params)
    #puts 'params=' + params.inspect
    q_type = :all
    select_attributes=[]

    if params.size > 0
        q_type = params[0]
    end

    # Pad and Offset number attributes
    options = {}
    if params.size > 1
        options = params[1]
        #puts 'options=' + options.inspect
        #puts 'after collect=' + options.inspect
        convert_condition_params(options)
    end
#            puts 'params2=' + params.inspect

    results = q_type == :all ? [] : nil
    begin
        results=super(*params)
#                puts "RESULT=" + results.inspect
        #puts 'params3=' + params.inspect
        SimpleRecord.stats.selects += 1
        if q_type != :count
            cache_results(results)
            if results.is_a?(Array)
                results = SimpleRecord::ResultsArray.new(self, params, results, next_token)
            end
        end
    rescue Aws::AwsError, Aws::ActiveSdb::ActiveSdbError
#                puts "RESCUED: " + $!.message
        if ($!.message().index("NoSuchDomain") != nil)
            # this is ok
        elsif ($!.message() =~ @@regex_no_id)
            results = nil
        else
            raise $!
        end
    end
    return results
end

.first(*args) ⇒ Object



712
713
714
# File 'lib/simple_record.rb', line 712

def self.first(*args)
    find(:first, *args)
end

.get_encryption_keyObject



411
412
413
414
415
416
417
418
# File 'lib/simple_record.rb', line 411

def self.get_encryption_key()
    key = SimpleRecord.options[:encryption_key]
#            if key.nil?
#                puts 'WARNING: Encrypting attributes with your AWS Access Key. You should use your own :encryption_key so it doesn\'t change'
#                key = connection.aws_access_key_id # default to aws access key. NOT recommended in case you start using a new key
#            end
    return key
end

.inherited(base) ⇒ Object



141
142
143
144
145
146
147
148
149
150
# File 'lib/simple_record.rb', line 141

def self.inherited(base)
    #puts 'SimpleRecord::Base is inherited by ' + base.inspect
    Callbacks.setup_callbacks(base)

#            base.has_strings :id
    base.has_dates :created, :updated
    base.before_create :set_created, :set_updated
    base.before_update :set_updated

end

.paginate(options = {}) ⇒ Object

This gets less and less efficient the higher the page since SimpleDB has no way to start at a specific row. So it will iterate from the first record and pull out the specific pages.



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/simple_record.rb', line 722

def self.paginate(options={})
#            options = args.pop
    puts 'paginate options=' + options.inspect if SimpleRecord.logging?
    page     = options[:page] || 1
    per_page = options[:per_page] || self.per_page || 50
    total    = options[:total_entries]
    options[:limit] = page * per_page
    fr = find(:all, options)
    puts 'fr.size=' + fr.size.to_s
    ret = []
    i = 0
    p = 1
    fr.each do |x|
#                puts 'x=' + x.inspect
        if p == page
#                    puts 'adding'
            ret << x
        end
        i += 1
        if i > 0 && i % per_page == 0
            p += 1
            if p > page
                break
            end
        end
    end
    ret
end

.quote_regexp(a, re) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/simple_record.rb', line 625

def self.quote_regexp(a, re)
    a =~ re
    #was there a match?
    if $&
        before=$`
        middle=$&
        after=$'

        before =~ /'$/ #is there already a quote immediately before the match?
        unless $&
            return "#{before}'#{middle}'#{quote_regexp(after, re)}" #if not, put quotes around the match
        else
            return "#{before}#{middle}#{quote_regexp(after, re)}" #if so, assume it is quoted already and move on
        end
    else
        #no match, just return the string
        return a
    end
end

.sanitize_sql(*params) ⇒ Object



788
789
790
# File 'lib/simple_record.rb', line 788

def self.sanitize_sql(*params)
    return ActiveRecord::Base.sanitize_sql(*params)
end

.select(*params) ⇒ Object



704
705
706
# File 'lib/simple_record.rb', line 704

def self.select(*params)
    return find(*params)
end

.set_domain_name(table_name) ⇒ Object

Sets the domain name for this class



190
191
192
193
194
# File 'lib/simple_record.rb', line 190

def self.set_domain_name(table_name)
    # puts 'setting domain name for class ' + self.inspect + '=' + table_name
    #@domain_name_for_class = table_name
    super
end

.set_domain_prefix(prefix) ⇒ Object

If you want a domain prefix for all your models, set it here.



179
180
181
182
# File 'lib/simple_record.rb', line 179

def self.set_domain_prefix(prefix)
    #puts 'set_domain_prefix=' + prefix
    self.domain_prefix = prefix
end

.set_table_name(table_name) ⇒ Object

Same as set_table_name



185
186
187
# File 'lib/simple_record.rb', line 185

def self.set_table_name(table_name)
    set_domain_name table_name
end

.table_nameObject



792
793
794
# File 'lib/simple_record.rb', line 792

def self.table_name
    return domain
end

Instance Method Details

#[](attribute) ⇒ Object



265
266
267
# File 'lib/simple_record.rb', line 265

def []( attribute)
    super
end

#[]=(attribute, values) ⇒ Object



260
261
262
263
# File 'lib/simple_record.rb', line 260

def []=(attribute, values)
    make_dirty(attribute, values)
    super
end

#cache_storeObject



288
289
290
# File 'lib/simple_record.rb', line 288

def cache_store
    @@cache_store
end

#changedObject



796
797
798
# File 'lib/simple_record.rb', line 796

def changed
    return @dirty.keys
end

#changed?Boolean



800
801
802
# File 'lib/simple_record.rb', line 800

def changed?
    return @dirty.size > 0
end

#changesObject



804
805
806
807
808
809
# File 'lib/simple_record.rb', line 804

def changes
    ret = {}
    #puts 'in CHANGES=' + @dirty.inspect
    @dirty.each_pair {|key, value| ret[key] = [value, get_attribute(key)]}
    return ret
end

#clear_errorsObject



256
257
258
# File 'lib/simple_record.rb', line 256

def clear_errors
    @errors=SimpleRecord_errors.new
end

#defined_attributes_localObject



153
154
155
156
157
# File 'lib/simple_record.rb', line 153

def defined_attributes_local
    #puts 'local defined_attributes'
    ret = self.class.defined_attributes
    ret.merge!(self.class.superclass.defined_attributes) if self.class.superclass.respond_to?(:defined_attributes)
end

#deleteObject



522
523
524
# File 'lib/simple_record.rb', line 522

def delete()
    super
end

#delete_niled(to_delete) ⇒ Object



600
601
602
603
604
605
606
607
# File 'lib/simple_record.rb', line 600

def delete_niled(to_delete)
#            puts 'to_delete=' + to_delete.inspect
    if to_delete.size > 0
#      puts 'Deleting attributes=' + to_delete.inspect
        SimpleRecord.stats.deletes += 1
        delete_attributes to_delete
    end
end

#destroyObject



526
527
528
# File 'lib/simple_record.rb', line 526

def destroy
    return run_before_destroy && delete && run_after_destroy
end

#domainObject



197
198
199
# File 'lib/simple_record.rb', line 197

def domain
    self.class.domain # super # super.domain
end

#domain_ok(ex) ⇒ Object



292
293
294
295
296
297
298
299
# File 'lib/simple_record.rb', line 292

def domain_ok(ex)
    if (ex.message().index("NoSuchDomain") != nil)
        puts "Creating new SimpleDB Domain: " + domain
        self.class.create_domain
        return true
    end
    return false
end

#get_attribute(arg) ⇒ 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.



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/simple_record.rb', line 533

def get_attribute(arg)
#            puts "GET #{arg}"
    # Check if this arg is already converted
    arg_s = arg.to_s
#            instance_var = ("@" + arg_s)
#            puts "defined?(#{instance_var.to_sym}) " + (defined?(instance_var.to_sym)).inspect
#            if defined?(instance_var.to_sym) # this returns "method" for some reason??
#            puts "attribute #{instance_var} is defined"
    @attributes_rb = {} unless @attributes_rb # was getting errors after upgrade.
    ret = @attributes_rb[arg_s] # instance_variable_get(instance_var)
#            puts 'ret from rb=' + ret.inspect
    return ret if !ret.nil?
#            end
    ret = get_attribute_sdb(arg)
#            puts 'ret from atts=' + ret.inspect
    ret = sdb_to_ruby(arg, ret)
#            puts 'ret from atts to rb=' + ret.inspect
#            puts "Setting instance var #{arg_s} to #{ret}"
#            instance_variable_set(instance_var, ret)
    @attributes_rb[arg_s] = ret
    return ret
end

#get_attribute_sdb(name) ⇒ Object



210
211
212
213
214
215
216
# File 'lib/simple_record.rb', line 210

def get_attribute_sdb(name)
#            arg = arg.to_s
#            puts "get_attribute_sdb(#{arg}) - #{arg.class.name}"
#            puts 'self[]=' + self.inspect
    ret = strip_array(@attributes[sdb_att_name(name)])
    return ret
end

#get_atts_to_deleteObject



458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/simple_record.rb', line 458

def get_atts_to_delete
    # todo: this should use the @dirty hash now
    to_delete = []
    @attributes.each do |key, value|
#                puts 'key=' + key.inspect + ' value=' + value.inspect
        if value.nil? || (value.is_a?(Array) && value.size == 0) || (value.is_a?(Array) && value.size == 1 && value[0] == nil)
            to_delete << key
            @attributes.delete(key)
        end
    end
    return to_delete
end

#hashObject



816
817
818
819
# File 'lib/simple_record.rb', line 816

def hash
    # same as ActiveRecord
    id.hash
end

#initialize_base(attrs = {}) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/simple_record.rb', line 119

def initialize_base(attrs={})

    #we have to handle the virtuals.
    Attributes.handle_virtuals(attrs)

    @errors=SimpleRecord_errors.new
    @dirty = {}

    @attributes = {} # sdb values
    @attributes_rb = {} # ruby values
    @new_record = true

end

#initialize_from_db(attrs = {}) ⇒ Object



133
134
135
136
137
138
# File 'lib/simple_record.rb', line 133

def initialize_from_db(attrs={})
    initialize_base(attrs)
    attrs.each_pair do |k, v|
        @attributes[k.to_s] = v
    end
end

#invalid?Boolean



323
324
325
# File 'lib/simple_record.rb', line 323

def invalid?
    !valid?
end

#make_dirty(arg, value) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/simple_record.rb', line 240

def make_dirty(arg, value)
    sdb_att_name = sdb_att_name(arg)
    arg = arg.to_s

#            puts "Marking #{arg} dirty with #{value}"
    if @dirty.include?(sdb_att_name)
        old = @dirty[sdb_att_name]
#                puts "#{sdb_att_name} was already dirty #{old}"
        @dirty.delete(sdb_att_name) if value == old
    else
        old = get_attribute(arg)
#                puts "dirtifying #{sdb_att_name} old=#{old.inspect} to new=#{value.inspect}"
        @dirty[sdb_att_name] = old if value != old
    end
end

#mark_as_oldObject



811
812
813
814
# File 'lib/simple_record.rb', line 811

def mark_as_old
    super
    @dirty = {}
end

#new_record?Boolean



318
319
320
321
# File 'lib/simple_record.rb', line 318

def new_record?
    # todo: new_record in activesdb should align with how we're defining a new record here, ie: if id is nil
    super
end

#pre_save(options) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/simple_record.rb', line 421

def pre_save(options)

    is_create = self[:id].nil?
    ok = run_before_validation && (is_create ? run_before_validation_on_create : run_before_validation_on_update)
    return false unless ok

    validate()

    is_create ? validate_on_create : validate_on_update
#      puts 'AFTER VALIDATIONS, ERRORS=' + errors.inspect
    if (!@errors.nil? && @errors.length > 0 )
#        puts 'THERE ARE ERRORS, returning false'
        return false
    end

    ok = run_after_validation && (is_create ? run_after_validation_on_create : run_after_validation_on_update)
    return false unless ok

    ok = respond_to?('before_save') ? before_save : true
    if ok
        if is_create && respond_to?('before_create')
            ok = before_create
        elsif !is_create && respond_to?('before_update')
            ok = before_update
        end
    end
    if ok
        ok = run_before_save && (is_create ? run_before_create : run_before_update)
    end
    if ok
        # Now translate all fields into SimpleDB friendly strings
#                convert_all_atts_to_sdb()
    end
    ok
end

#reloadObject



609
610
611
# File 'lib/simple_record.rb', line 609

def reload
    super()
end

#save(options = {}) ⇒ Object

Options:

- :except => Array of attributes to NOT save
- :dirty => true - Will only store attributes that were modified. To make it save regardless and have it update the :updated value, include this and set it to false.


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.rb', line 345

def save(options={})
#            puts 'SAVING: ' + self.inspect
    # todo: Clean out undefined values in @attributes (in case someone set the attributes hash with values that they hadn't defined)
    clear_errors
    # todo: decide whether this should go before pre_save or after pre_save? pre_save dirties "updated" and perhaps other items due to callbacks
    if options[:dirty]
#                puts '@dirtyA=' + @dirty.inspect
        return true if @dirty.size == 0 # Nothing to save so skip it
    end
    is_create = self[:id].nil?
    ok = pre_save(options)
    if ok
        begin
            if options[:dirty]
#                        puts '@dirty=' + @dirty.inspect
                return true if @dirty.size == 0 # This should probably never happen because after pre_save, created/updated dates are changed
                options[:dirty_atts] = @dirty
            end
            to_delete = get_atts_to_delete # todo: this should use the @dirty hash now
            SimpleRecord.stats.puts += 1
#                    puts 'SELF BEFORE super=' + self.inspect
            if super(options)
#                        puts 'SELF AFTER super=' + self.inspect
                self.class.cache_results(self)
                delete_niled(to_delete)
                if (is_create ? run_after_create : run_after_update) && run_after_save
#                            puts 'all good?'
                    return true
                else
                    return false
                end
            else
                return false
            end
        rescue Aws::AwsError
            # puts "RESCUED in save: " + $!
            if (domain_ok($!))
                if !@create_domain_called
                    @create_domain_called = true
                    save(options)
                else
                    raise $!
                end
            else
                raise $!
            end
        end
    else
        #@debug = "not saved"
        return false
    end
end

#save!(options = {}) ⇒ Object



398
399
400
# File 'lib/simple_record.rb', line 398

def save!(options={})
    save(options) || raise(RecordNotSaved)
end

#save_with_validation!(options = {}) ⇒ Object



402
403
404
405
406
407
408
# File 'lib/simple_record.rb', line 402

def save_with_validation!(options={})
    if valid?
        save
    else
        raise RecordInvalid.new(self)
    end
end

#sdb_att_name(name) ⇒ Object



218
219
220
221
222
223
224
# File 'lib/simple_record.rb', line 218

def sdb_att_name(name)
    att_meta = defined_attributes_local[name.to_sym]
    if att_meta.type == :belongs_to
        return "#{name}_id"
    end
    name.to_s
end

#set(name, value, dirtify = true) ⇒ Object



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/simple_record.rb', line 556

def set(name, value, dirtify=true)
#            puts "SET #{name}=#{value.inspect}"
#            puts "self=" + self.inspect
    att_meta = defined_attributes_local[name.to_sym]
    if att_meta.nil?
        # check if it ends with id and see if att_meta is there
        ends_with = name.to_s[-3, 3]
        if ends_with == "_id"
#                    puts 'ends with id'
            n2 = name.to_s[0, name.length-3]
#                    puts 'n2=' + n2
            att_meta = defined_attributes_local[n2.to_sym]
#                    puts 'defined_attributes_local=' + defined_attributes_local.inspect
            attname = name.to_s
            attvalue = value
            name = n2
        end
        return if att_meta.nil?
    else
        if att_meta.type == :belongs_to
            attname = name.to_s + '_id'
            attvalue = value.nil? ? nil : value.id
        else
            attname = name.to_s
            attvalue = att_meta.init_value(value)
#                  attvalue = value
            #puts 'converted ' + value.inspect + ' to ' + attvalue.inspect
        end
    end
    attvalue = strip_array(attvalue)
    make_dirty(name, attvalue) if dirtify
#            puts "ARG=#{attname.to_s} setting to #{attvalue}"
    sdb_val = ruby_to_sdb(name, attvalue)
#            puts "sdb_val=" + sdb_val.to_s
    @attributes[attname] = sdb_val
#            attvalue = wrap_if_required(name, attvalue, sdb_val)
#            puts 'attvalue2=' + attvalue.to_s
    @attributes_rb.delete(name.to_s) # todo: we should set the value here so it doesn't reget anything


#            instance_var = "@" + attname.to_s
#            instance_variable_set(instance_var, attvalue)
end

#set_createdObject



270
271
272
273
274
275
276
277
# File 'lib/simple_record.rb', line 270

def set_created
#    puts 'SETTING CREATED'
    #    @created = DateTime.now
    set(:created, Time.now)
#            self[:created] = Time.now
#    @tester = 'some test value'
    #    self[:tester] = 'some test value'
end

#set_updatedObject



279
280
281
282
283
284
285
# File 'lib/simple_record.rb', line 279

def set_updated
    #puts 'SETTING UPDATED'
    #    @updated = DateTime.now
    set(:updated, Time.now)
#            self[:updated] = Time.now
#    @tester = 'some test value updated'
end

#strip_array(arg) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/simple_record.rb', line 226

def strip_array(arg)
    if arg.class==Array
        if arg.length==1
            ret = arg[0]
        else
            ret = arg
        end
    else
        ret = arg
    end
    return ret
end

#update_attributes(atts) ⇒ Object



614
615
616
617
# File 'lib/simple_record.rb', line 614

def update_attributes(atts)
    set_attributes(atts)
    save
end

#update_attributes!(atts) ⇒ Object



619
620
621
622
# File 'lib/simple_record.rb', line 619

def update_attributes!(atts)
    set_attributes(atts)
    save!
end

#valid?Boolean



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/simple_record.rb', line 301

def valid?
    errors.clear

#            run_callbacks(:validate)
    validate

    if new_record?
#                run_callbacks(:validate_on_create)
        validate_on_create
    else
#                run_callbacks(:validate_on_update)
        validate_on_update
    end

    errors.empty?
end

#validateObject



327
328
329
# File 'lib/simple_record.rb', line 327

def validate
    true
end

#validate_on_createObject



331
332
333
# File 'lib/simple_record.rb', line 331

def validate_on_create
    true
end

#validate_on_updateObject



335
336
337
# File 'lib/simple_record.rb', line 335

def validate_on_update
    true
end