app/strategies/passage_updater.rb
# Process a single Passage row.
#
# The row will be:
# - updated, when the row exists;
# - created with the specified values, when not found;
# - deleted, when the timing specified is nil and the row itself is existing.
#
# The method will act according to the presence of the first 2 parameters,
# the others are not required and can be nil.
#
# When specified, the MeetingIndividualResult instance (mir_id) parameter will take
# precedence over any other supplied meeting_program_id, swimmer_id & team_id.
# (These 3 must all be present in order to be used when the +mir+ parameter is +nil+)
#
# (Thus, this updater supports also the editing of Passage rows w/o the existance
# of a parent MIR row.)
#
# The method updates also the internal SQL diff log file accordingly.
#
# == Returns:
#
# The updated/created Passage instance, or +true+ in case of deletion;
#
# Result is +false+ when the row was not found and the deletion was skipped,
# or +nil+ only in case of any errors during the update/create transaction.
#
Process a single Passage row.
The row will be:
updated, when the row exists;
created with the specified values, when not found;
deleted, when the timing specified is nil and the row itself is existing.

The method will act according to the presence of the first 2 parameters,
the others are not required and can be nil.

When specified, the MeetingIndividualResult instance (mir_id) parameter will take
precedence over any other supplied meeting_program_id, swimmer_id & team_id.
(These 3 must all be present in order to be used when the +mir+ parameter is +nil+)

(Thus, this updater supports also the editing of Passage rows w/o the existance
of a parent MIR row.)

The method updates also the internal SQL diff log file accordingly.



The updated/created Passage instance, or +true+ in case of deletion.

Result is +false+ when the row was not found and the deletion was skipped,
or +nil+ only in case of any errors during the update/create transaction.
Process a single Passage row . The row will be : updated when the row exists ; created with the specified values when not found ; deleted when the timing specified is nil and the row itself is existing . The method will act according to the presence of the first 2 parameters the others are not required and can be nil . When specified the MeetingIndividualResult instance ( mir_id ) parameter will take precedence over any other supplied meeting_program_id swimmer_id & team_id . ( These 3 must all be present in order to be used when the + mir + parameter is + nil + ) ( Thus this updater supports also the editing of Passage rows w / o the existance of a parent MIR row . ) The method updates also the internal SQL diff log file accordingly . The updated / created Passage instance or + true + in case of deletion . Result is + false + when the row was not found and the deletion was skipped or + nil + only in case of any errors during the update / create transaction .
def process!( passage, incremental_timing_text_value, passage_type_id = nil, mir_id = nil,
                reaction_time_text = nil, swimmer_id = nil, team_id = nil, meeting_program_id = nil )
    timing_instance = TimingParser.parse( incremental_timing_text_value ) if incremental_timing_text_value
    reaction_time   = TimingParser.parse( reaction_time_text ) if reaction_time_text
    mir = MeetingIndividualResult.find_by_id( mir_id )
    return nil if passage.nil? && timing_instance.nil? 
    if passage && timing_instance.nil?                
      return delete_existing_row!( passage )
    elsif passage && timing_instance                  
      Passage.transaction do
        edit_existing_row!( passage, timing_instance, reaction_time,
                            meeting_program_id, swimmer_id, team_id )
      end
    elsif passage.nil? && timing_instance           
      Passage.transaction do
        create_new_row!( mir, passage_type_id, timing_instance, reaction_time,
                         meeting_program_id, swimmer_id, team_id )
      end
    end
  rescue
    puts "RESCUE: '#{ $! }'"
    puts caller
    return nil
  end
def process! ( passage , incremental_timing_text_value , passage_type_id = nil , mir_id = nil , reaction_time_text = nil , swimmer_id = nil , team_id = nil , meeting_program_id = nil ) timing_instance = TimingParser . parse ( incremental_timing_text_value ) if incremental_timing_text_value reaction_time = TimingParser . parse ( reaction_time_text ) if reaction_time_text mir = MeetingIndividualResult . find_by_id ( mir_id ) return nil if passage . nil? && timing_instance . nil? if passage && timing_instance . nil? return delete_existing_row! ( passage ) elsif passage && timing_instance Passage . transaction do edit_existing_row! ( passage , timing_instance , reaction_time , meeting_program_id , swimmer_id , team_id ) end elsif passage . nil? && timing_instance Passage . transaction do create_new_row! ( mir , passage_type_id , timing_instance , reaction_time , meeting_program_id , swimmer_id , team_id ) end end rescue puts "RESCUE: '#{ $! }'" puts caller return nil end
Process a single Passage row.
Process a single Passage row .
# (nothing to be done) # DEBUG #    puts "timing: '#{ incremental_timing_text_value }' => #{ timing_instance }\r\nreaction: '#{ reaction_time_text }' => #{ reaction_time }" # --- DELETE --- # --- UPDATE --- # --- CREATE --- # DEBUG
passage
<not_specific>
incremental_timing_text_value
<not_specific>
passage_type_id
<not_specific>
mir_id
<not_specific>
reaction_time_text
<not_specific>
swimmer_id
<not_specific>
team_id
<not_specific>
meeting_program_id
<not_specific>