module CustomFields::Types::Default::Field

Public Instance Methods

collect_default_diff(memo) click to toggle source

Build the mongodb updates based on the new state of the field

@param [ Hash ] memo Store the updates

@return [ Hash ] The memo object upgraded

# File lib/custom_fields/types/default.rb, line 14
def collect_default_diff(memo)
  # puts "collect_default_diff #{self.name}: #{self.persisted?} / #{self.destroyed?}" # DEBUG
  if persisted?
    if destroyed?
      memo['$unset'][name] = 1
    elsif changed?
      if changes.key?('name')
        old_name, new_name = changes['name']
        memo['$rename'][old_name] = new_name
      end
    end
  end

  (memo['$set']['custom_fields_recipe.rules'] ||= []) << to_recipe

  memo
end