app/models/run.rb
# convert self(entity_ref) to Run entity and put it to DB.
#  root_entity is owner(assoc_entity) of self
#  root_since is demanded since for modification to root_entity
#  omit root_entity and root_since at initial entry.
convert self(entity_ref) to Run entity and put it to DB.
root_entity is owner(assoc_entity) of self
root_since is demanded since for modification to root_entity
omit root_entity and root_since at initial entry.
convert self ( entity_ref ) to Run entity and put it to DB . root_entity is owner ( assoc_entity ) of self root_since is demanded since for modification to root_entity omit root_entity and root_since at initial entry .
def put(root_entity = nil, root_since = nil)
    set_of_all_errors = []
    (value = content[Run::Literal.to_s])  and return value
    (value = content[Run::Per_Se.to_s]) and return model.find(value.to_i)
    receiver = model.new(self.content)
    receiver.entity_id = self.entity_id
    begin
      receiver.respond_to?("modifier!") and receiver.modifier!
    rescue ActiveRecord::RecordInvalid => e
      set_of_all_errors << e
    end
    since = receiver.send(Run::Since)
    root_entity.nil? and root_since = since
    root_since ||= Run.get_action_time
    since ||=  root_since
    locked_states = receiver._received_states_to_be_locked_    
    Run.transaction do    
      receiver._assoc_dependee.to_a.each do |assoc|
        assoc.assoc_entity = receiver
        dependee_refs = assoc.map(&:to_entity_ref).select{ |t| t.content[Run::Assoc_Deleted.to_s].blank? }
        if dependee_refs.blank?
          assoc.disconnect()  
        elsif dependee_refs.size > 1
          fail ArgumentError, "dependee should be only one."
        else
          dependee_ref = dependee_refs.first
          dependee = dependee_ref.put(receiver, root_since)
          assoc.connect(dependee)
          set_of_all_errors +=  (dependee.set_of_all_errors || [])
        end
      end
      begin
        real_content = receiver.attributes
        pure_entity = 
          if new? 
            entity = model.new_run(real_content)
            entity.entity_id = self.entity_id
            entity.since = since
            entity.create_run!
          else
            update_content = extract_updating_content(real_content)
            original = model.find_entity(self.entity_id) 
            original.update_run!(since, update_content, locked_states)
          end
      rescue ActiveRecord::RecordInvalid => e
        record = e.record 
        record.set_of_all_errors = set_of_all_errors << e
        fail ActiveRecord::RecordInvalid.new(record)
      end
      root_entity.nil? and root_entity = pure_entity
      receiver._assoc_dependant.to_a.each do |assoc|
        assoc.assoc_entity = pure_entity
        assoc.each do |target_ref_list|
          target_ref_list.keys.each do |key|
            target_ref = {key => target_ref_list[key]}.to_entity_ref 
            target_ref.content[Run::Assoc_Deleted.to_s].blank? ? 
               assoc.connect(target_ref) : assoc.disconnect(target_ref)
            dependant = target_ref.put(root_entity, root_since)
            set_of_all_errors += (dependant.set_of_all_errors || [])
          end
        end
      end
    end
    root_entity.set_of_all_errors = set_of_all_errors
    return root_entity
  end
def put ( root_entity = nil , root_since = nil ) set_of_all_errors = [ ] ( value = content [ Run :: Literal . to_s ] ) and return value ( value = content [ Run :: Per_Se . to_s ] ) and return model . find ( value . to_i ) receiver = model . new ( self . content ) receiver . entity_id = self . entity_id begin receiver . respond_to? ( "modifier!" ) and receiver . modifier! rescue ActiveRecord :: RecordInvalid => e set_of_all_errors << e end since = receiver . send ( Run :: Since ) root_entity . nil? and root_since = since root_since ||= Run . get_action_time since ||= root_since locked_states = receiver . _received_states_to_be_locked_ Run . transaction do receiver . _assoc_dependee . to_a . each do | assoc | assoc . assoc_entity = receiver dependee_refs = assoc . map ( & :to_entity_ref ) . select { | t | t . content [ Run :: Assoc_Deleted . to_s ] . blank? } if dependee_refs . blank? assoc . disconnect ( ) elsif dependee_refs . size > 1 fail ArgumentError , "dependee should be only one." else dependee_ref = dependee_refs . first dependee = dependee_ref . put ( receiver , root_since ) assoc . connect ( dependee ) set_of_all_errors += ( dependee . set_of_all_errors || [ ] ) end end begin real_content = receiver . attributes pure_entity = if new? entity = model . new_run ( real_content ) entity . entity_id = self . entity_id entity . since = since entity . create_run! else update_content = extract_updating_content ( real_content ) original = model . find_entity ( self . entity_id ) original . update_run! ( since , update_content , locked_states ) end rescue ActiveRecord :: RecordInvalid => e record = e . record record . set_of_all_errors = set_of_all_errors << e fail ActiveRecord :: RecordInvalid . new ( record ) end root_entity . nil? and root_entity = pure_entity receiver . _assoc_dependant . to_a . each do | assoc | assoc . assoc_entity = pure_entity assoc . each do | target_ref_list | target_ref_list . keys . each do | key | target_ref = { key => target_ref_list [ key ] } . to_entity_ref target_ref . content [ Run :: Assoc_Deleted . to_s ] . blank? ? assoc . connect ( target_ref ) : assoc . disconnect ( target_ref ) dependant = target_ref . put ( root_entity , root_since ) set_of_all_errors += ( dependant . set_of_all_errors || [ ] ) end end end end root_entity . set_of_all_errors = set_of_all_errors return root_entity end
convert self(entity_ref) to Run entity and put it to DB.
convert self ( entity_ref ) to Run entity and put it to DB .
# to accumulate errors of ActiveRecored::RecordInvalid # receive all attributes(including virtual ones) in content and assign their values # modify attributes if receiver has method "modifier!" # demanded since for root entity # default root_entity # since setting for dependees and depandants # put dependees if any and connect them to receiver. # if no dependee given, disconnect association with dependee. # disconnect association to dependee. # put pure part of receiver to DB; the result is pure_entity # record with save validation errors # set root_entity pure_emntity at initial entry # connect all dependants if any to the pure_entity and put them.
root_entity
<not_specific>
root_since
<not_specific>