0
@@ -47,11 +47,17 @@ module PreferenceFu
0
@preferences_object ||= Preferences.new(read_attribute(preferences_column.to_sym), self)
0
+ def preferences=(prefs)
0
+ preferences.store(prefs)
0
attr_accessor :instance, :options
0
def initialize(prefs, instance)
0
@@ -73,6 +79,16 @@ module PreferenceFu
0
+ @options.each_value do |hsh|
0
+ yield hsh[:key], self[hsh[:key]]
0
instance_variable_get("@#{key}")
0
@@ -83,6 +99,13 @@ module PreferenceFu
0
+ # used for mass assignment of preferences, such as a hash from params
0
+ prefs.each do |key, value|
0
+ end if prefs.respond_to?(:each)
0
@options.inject(0) do |bv, (idx, hsh)|
0
bv |= instance_variable_get("@#{hsh[:key]}") ? idx : 0
0
@@ -112,97 +135,4 @@ module PreferenceFu
0
receiver.extend ClassMethods
0
receiver.send :include, InstanceMethods
0
-# def has_preferences(*attrs)
0
-# Preferences.set_options = *attrs
0
-# composed_of :preferences, :class_name => 'PreferenceFu::Preferences'
0
-# cattr_accessor :options
0
-# def set_options=(hsh)
0
-# idx = 0; @@options = {}
0
-# hsh.each do |pref, default|
0
-# @@options[2**idx] = { :key => pref.to_sym, :default => default }
0
-# attr_reader pref.to_sym
0
-# def initialize(prefs)
0
-# if prefs.nil? or prefs.is_a?(Hash)
0
-# @@options.each do |idx, hsh|
0
-# instance_variable_set("@#{hsh[:key]}", hsh[:default])
0
-# prefs.each do |key, value|
0
-# instance_variable_set("@#{key}", true) if is_true(value)
0
-# elsif prefs.is_a?(Numeric)
0
-# @@options.each do |idx, hsh|
0
-# instance_variable_set("@#{hsh[:key]}", (prefs & idx) != 0 ? true : false)
0
-# # true if key exists and is true
0
-# instance_variable_get("@#{key}")
0
-# # composed_of is immutable, and thus can only update with a new object
0
-# # idx, hsh = lookup(key)
0
-# # @@options[idx][:value] = value
0
-# # instance_variable_set("@#{key}", value)
0
-# Preferences.new(:download_stuff => true)
0
-# @@options.inject(0) do |bv, (idx, hsh)|
0
-# bv |= instance_variable_get("@#{hsh[:key]}") ? idx : 0
0
-# when true, 1, /1|y|yes/i then true
0
-# @@options.find { |idx, hsh| hsh[:key] == key.to_sym }
0
\ No newline at end of file
0
\ No newline at end of file
Comments
No one has commented yet.