lib/inventory_refresh/inventory_object.rb
def assign_only_newest(full_row_version_attr, partial_row_version_attr, attributes, data, k, v)
      # If timestamps are in play, we will set only attributes that are newer
      specific_attr_timestamp = attributes[partial_row_version_attr].try(:[], k)
      specific_data_timestamp = data[partial_row_version_attr].try(:[], k)

      assign = if !specific_attr_timestamp
                 # Data have no timestamp, we will ignore the check
                 true
               elsif specific_attr_timestamp && !specific_data_timestamp
                 # Data specific timestamp is nil and we have new specific timestamp
                 if data.key?(k)
                   if attributes[full_row_version_attr] >= data[full_row_version_attr]
                     # We can save if the full timestamp is bigger, if the data already contains the attribute
                     true
                   end
                 else
                   # Data do not contain the attribute, so we are saving the newest
                   true
                 end
                 true
               elsif specific_attr_timestamp > specific_data_timestamp
                 # both partial timestamps are there, newer must be bigger
                 true
               end

      if assign
        public_send("#{k}=", v) # Attribute is newer than current one, lets use it
        (data[partial_row_version_attr] ||= {})[k] = specific_attr_timestamp if specific_attr_timestamp # and set the latest timestamp
      end
    end
def assign_only_newest(full_row_version_attr, partial_row_version_attr, attributes, data, k, v)
      # If timestamps are in play, we will set only attributes that are newer
      specific_attr_timestamp = attributes[partial_row_version_attr].try(:[], k)
      specific_data_timestamp = data[partial_row_version_attr].try(:[], k)

      assign = if !specific_attr_timestamp
                 # Data have no timestamp, we will ignore the check
                 true
               elsif specific_attr_timestamp && !specific_data_timestamp
                 # Data specific timestamp is nil and we have new specific timestamp
                 if data.key?(k)
                   if attributes[full_row_version_attr] >= data[full_row_version_attr]
                     # We can save if the full timestamp is bigger, if the data already contains the attribute
                     true
                   end
                 else
                   # Data do not contain the attribute, so we are saving the newest
                   true
                 end
                 true
               elsif specific_attr_timestamp > specific_data_timestamp
                 # both partial timestamps are there, newer must be bigger
                 true
               end

      if assign
        public_send("#{k}=", v) # Attribute is newer than current one, lets use it
        (data[partial_row_version_attr] ||= {})[k] = specific_attr_timestamp if specific_attr_timestamp # and set the latest timestamp
      end
    end
def assign_only_newest ( full_row_version_attr , partial_row_version_attr , attributes , data , k , v ) # If timestamps are in play, we will set only attributes that are newer specific_attr_timestamp = attributes [ partial_row_version_attr ] . try ( :[] , k ) specific_data_timestamp = data [ partial_row_version_attr ] . try ( :[] , k ) assign = if ! specific_attr_timestamp # Data have no timestamp, we will ignore the check true elsif specific_attr_timestamp && ! specific_data_timestamp # Data specific timestamp is nil and we have new specific timestamp if data . key? ( k ) if attributes [ full_row_version_attr ] >= data [ full_row_version_attr ] # We can save if the full timestamp is bigger, if the data already contains the attribute true end else # Data do not contain the attribute, so we are saving the newest true end true elsif specific_attr_timestamp > specific_data_timestamp # both partial timestamps are there, newer must be bigger true end if assign public_send ( "#{k}=" , v ) # Attribute is newer than current one, lets use it ( data [ partial_row_version_attr ] ||= { } ) [ k ] = specific_attr_timestamp if specific_attr_timestamp # and set the latest timestamp end end
Assigns value based on the version attributes. If versions are specified, it asigns attribute only if it's
 newer than existing attribute.

 @param full_row_version_attr [Symbol] Attr name for full rows, allowed values are
        [:resource_timestamp, :resource_counter]
 @param partial_row_version_attr [Symbol] Attr name for partial rows, allowed values are
        [:resource_timestamps, :resource_counters]
 @param attributes [Hash] New attributes we are assigning
 @param data [Hash] Existing attributes of the InventoryObject
 @param k [Symbol] Name of the attribute we are assigning
 @param v [Object] Value of the attribute we are assigning
Assigns value based on the version attributes . If versions are specified it asigns attribute only if it s newer than existing attribute .