
class NilClass
  def method_missing(name, *args, &block)
  end
end

class Sequel::Model
end

class User < Sequel::Model

  plugin :validation_helpers

  def validate
    super
    validates_presence :email
  end

  def before_create
    super
    self.preferences = {:favorites => []}.to_json
    self.token = SecureRandom.hex(32)
    self.created_at = Time.now
    self.updated_at = Time.now
  end

  def before_update
    super
    self.updated_at = Time.now
  end

  def self.find_or_create_by_email(email)
    User.filter(:email => email).first or User.new(:email => email).save
  end

  def add_favorite(uuid)
    preferences = JSON.parse(self.preferences)
    preferences['favorites'].push(uuid).uniq!
    self.preferences = preferences.to_json
    self.save
  end

  def remove_favorite(uuid)
    preferences = JSON.parse(self.preferences)
    preferences['favorites'].delete_if {|f| f === uuid}
    self.preferences = preferences.to_json
    self.save
  end
end


class NilClass
  def method_missing(name, *args, &block)
  end
end

class Sequel::Model
end

class User < Sequel::Model

  plugin :validation_helpers

  def validate
    super
    validates_presence :email
  end

  def before_create
    super
    self.preferences = {:favorites => []}.to_json
    self.token = SecureRandom.hex(32)
    self.created_at = Time.now
    self.updated_at = Time.now
  end

  def before_update
    super
    self.updated_at = Time.now
  end

  def self.find_or_create_by_email(email)
    User.filter(:email => email).first or User.new(:email => email).save
  end

  def add_favorite(uuid)
    self.preferences.favorites.push(uuid).uniq!
    self.save
  end

  def remove_favorite(uuid)
    self.preferences.favorites.delete_if {|f| f === uuid}
    self.save
  end
end

Revert "need to parse out preferences before adding/removing favorites"
Revert "need to parse out preferences before adding/removing favorites"

This reverts commit 4b8ecce1c2f19662e7c96f6272ad90482e4f89b2.
