Class: IcfMasterTracker
- Inherits:
-
ActiveRecordShared
- Object
- ActiveRecord::Base
- ActiveRecordShared
- IcfMasterTracker
- Defined in:
- app/models/icf_master_tracker.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#attach_study_subject ⇒ Object
after_save :update_models.
- #flag_for_update ⇒ Object
- #ignorable_changes ⇒ Object
- #save_all_changes ⇒ Object
- #unignorable_changes ⇒ Object
Class Method Details
.update_models_flagged_for_update ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/icf_master_tracker.rb', line 79 def self.update_models_flagged_for_update puts "Searching for changed Icf Master Tracker records." changed_records = self.have_changed if changed_records.empty? puts "- Found no changed records." else puts "- Found #{changed_records} changed records." changed_records.each do |record| # record.last_update_attempted_at = Time.now # unless record.study_subject_id.nil? # try to update models # if successful # record.flagged_for_update = false # record.last_update_attempt_errors = nil # else # set last_update_attempt_error # leave flagged_for_update as true # end # else # record.last_update_attempt_errors = "study_subject is nil. Nothing to update." # leave flagged_for_update as true # end # record.save end end end |
Instance Method Details
#attach_study_subject ⇒ Object
after_save :update_models
39 40 41 42 43 |
# File 'app/models/icf_master_tracker.rb', line 39 def attach_study_subject unless study_subject_id self.study_subject = StudySubject.find_by_icf_master_id(self.Masterid) end end |
#flag_for_update ⇒ Object
55 56 57 |
# File 'app/models/icf_master_tracker.rb', line 55 def flag_for_update self.flagged_for_update = true unless unignorable_changes.empty? end |
#ignorable_changes ⇒ Object
45 46 47 48 49 |
# File 'app/models/icf_master_tracker.rb', line 45 def ignorable_changes # %w{id flagged_for_update study_subject_id Masterid created_at updated_at} %w{ id created_at updated_at flagged_for_update last_update_attempt_errors last_update_attempted_at } end |
#save_all_changes ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/icf_master_tracker.rb', line 59 def save_all_changes if new_record? IcfMasterTrackerChange.create( :icf_master_id => self.Masterid, # 5 t.date :master_tracker_date # Hmm. :new_tracker_record => true ) else unignorable_changes.each do |field,values| IcfMasterTrackerChange.create( :icf_master_id => self.Masterid, # 5 t.date :master_tracker_date # Hmm. :modified_column => field, :previous_value => values[0], :new_value => values[1] ) end end end |
#unignorable_changes ⇒ Object
51 52 53 |
# File 'app/models/icf_master_tracker.rb', line 51 def unignorable_changes changes.dup.delete_keys!(*ignorable_changes) end |