Sha256: 09b5b9b150a7ae513e4c176bfe6798855c39c22af71590edb2c50ed115aadf65

Contents?: true

Size: 582 Bytes

Versions: 2

Compression:

Stored size: 582 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!(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

2 entries across 2 versions & 1 rubygems

Version Path
user_preferences-1.0.2 lib/user_preferences/preference.rb
user_preferences-1.0.1 lib/user_preferences/preference.rb