app/models/run.rb
# convert run entity to entity_ref format
# option1 ...
#   nil ... full set of attributes with associated entities
#   :no_assocs ...  without associatiated entities.
#   :only_primary_attributes ... only id and run_id attributes for entities including associated entities.
# assoc_ref ... Hash. value should be array of strings of assoc names.
#   :only   ...  assocs to include
#   :except ... exclude assocs to include
convert run entity to entity_ref format
option1
nil ... full set of attributes with associated entities
:no_assocs ...  without associatiated entities.
convert run entity to entity_ref format option1 nil ... full set of attributes with associated entities : no_assocs ... without associatiated entities .
def to_entity_ref(option1 = nil, assoc_ref = {})
    entity_id = self.to_param
    content = {}
    attributes.each_pair do |attr, value|
      if value.is_a?(Time) or value.is_a?(DateTime)
        value = value.to_s(:db)
      end
      if [:no_assocs, :only_primary_attributes].include?(option1)
        if Primary_Attributes.include?(attr.to_s)
          content.merge! attr => value 
        end
      else
        content.merge! attr => value   
      end
    end 
    option1 == :no_assocs and return EntityRef.new( entity_id => content )
    _assoc_dependee.to_a.each do |assoc|
       content.merge! assoc.assoc_name => assoc.first.to_entity_ref(option1)
    end
    _assoc_dependant.to_a.each do |assoc|
      if assoc_ref.blank? || ((assoc_ref[:only] && assoc_ref[:only].include?(assoc.assoc_name.to_s)) || (assoc_ref[:exclude] && !assoc_ref[:exclude].include?(assoc.assoc_name.to_s)))
        assoc_content = []
        assoc.each do |target|
          target_ref = target.to_entity_ref(option1)
          assoc_content <<  target_ref
        end
        content.merge! assoc.assoc_name => assoc_content
      end
    end
    EntityRef.new( entity_id => content )
  end
def to_entity_ref ( option1 = nil , assoc_ref = { } ) entity_id = self . to_param content = { } attributes . each_pair do | attr , value | if value . is_a? ( Time ) or value . is_a? ( DateTime ) value = value . to_s ( :db ) end if [ :no_assocs , :only_primary_attributes ] . include? ( option1 ) if Primary_Attributes . include? ( attr . to_s ) content . merge! attr => value end else content . merge! attr => value end end option1 == :no_assocs and return EntityRef . new ( entity_id => content ) _assoc_dependee . to_a . each do | assoc | content . merge! assoc . assoc_name => assoc . first . to_entity_ref ( option1 ) end _assoc_dependant . to_a . each do | assoc | if assoc_ref . blank? || ( ( assoc_ref [ :only ] && assoc_ref [ :only ] . include? ( assoc . assoc_name . to_s ) ) || ( assoc_ref [ :exclude ] && ! assoc_ref [ :exclude ] . include? ( assoc . assoc_name . to_s ) ) ) assoc_content = [ ] assoc . each do | target | target_ref = target . to_entity_ref ( option1 ) assoc_content << target_ref end content . merge! assoc . assoc_name => assoc_content end end EntityRef . new ( entity_id => content ) end
convert run entity to entity_ref format
option1 ...
nil ... full set of attributes with associated entities
:no_assocs ...  without associatiated entities.
convert run entity to entity_ref format option1 ... nil ... full set of attributes with associated entities : no_assocs ... without associatiated entities .
# transform time attributes to db strings to keep coherency of time format. # for associations
option1
<not_specific>
assoc_ref
<not_specific>