Sha256: a79f6ef676a962984946b992489a2fd752bd9d51a6fbbbd3e97225a44922ad06

Contents?: true

Size: 593 Bytes

Versions: 1

Compression:

Stored size: 593 Bytes

Contents

class UserPreferences::Preference < ActiveRecord::Base
  self.table_name = 'preferences'
  belongs_to :user
  validates_uniqueness_of :name, scope: [:user_id, :category]
  validates_presence_of :user_id, :category, :name
  validates :value, inclusion: { in: ->(p) { p.permitted_values }}

  delegate :binary?, :default, :permitted_values, :lookup, :to_db, to: :definition

  def update_value!(v)
    update_attributes!(value: v)
  end

  def value
    lookup(attributes['value'])
  end

  def value=(v)
    super(to_db(v))
  end

  def definition
    UserPreferences[category, name]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
user_preferences-1.0.0 lib/user_preferences/preference.rb