module UserPreferences::HasPreferences
Public Class Methods
with_preference(category, name, value)
click to toggle source
# File lib/user_preferences/has_preferences.rb, line 19 def self.with_preference(category, name, value) definition = UserPreferences[category, name] db_value = definition.to_db(value) join = %Q{ %s join #{UserPreferences::Preference.table_name} p on p.category = '#{category}' and p.name = '#{name}' and p.user_id = #{self.table_name}.id } if value != definition.default joins(join % 'inner').where("p.value = #{db_value}") else joins(join % 'left').where("p.value = #{db_value} or p.id is null") end end
Public Instance Methods
preferences(category)
click to toggle source
# File lib/user_preferences/has_preferences.rb, line 14 def preferences(category) @_preference_apis ||= {} @_preference_apis[category] ||= UserPreferences::API.new(category, saved_preferences) end