<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,7 @@
 == master
 
+* Rename Preference#attribute to #name to avoid conflicts with reserved methods in ActiveRecord
+
 == 0.3.0 / 2009-04-13
 
 * Add dependency on Rails 2.3</diff>
      <filename>CHANGELOG.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -5,20 +5,20 @@
 # In addition to simple named preferences, preferences can also be grouped by
 # a particular value, be it a string or ActiveRecord object.  For example, a
 # User may have a preferred color for a particular Car.  In this case, the
-# +owner+ is the User, the +attribute+ is the color, and the +group+ is the Car.
-# This allows preferences to have a sort of context around them.
+# +owner+ is the User record, the +name+ is &quot;color&quot;, and the +group+ is the
+# Car record.  This allows preferences to have a sort of context around them.
 class Preference &lt; ActiveRecord::Base
-  belongs_to  :owner, :polymorphic =&gt; true
-  belongs_to  :group, :polymorphic =&gt; true
+  belongs_to :owner, :polymorphic =&gt; true
+  belongs_to :group, :polymorphic =&gt; true
   
-  validates_presence_of :attribute, :owner_id, :owner_type
+  validates_presence_of :name, :owner_id, :owner_type
   validates_presence_of :group_type, :if =&gt; :group_id?
   
   class &lt;&lt; self
     # Splits the given group into its corresponding id and type. For simple
-    # primitives, the id will be nil.  For complex types, specifically ActiveRecord
-    # objects, the id is the unique identifier stored in the databse for the
-    # record.
+    # primitives, the id will be nil.  For complex types, specifically
+    # ActiveRecord objects, the id is the unique identifier stored in the
+    # database for the record.
     # 
     # For example,
     # 
@@ -36,7 +36,7 @@ class Preference &lt; ActiveRecord::Base
     end
   end
   
-  # The definition for the attribute
+  # The definition of the preference as defined in the owner's model
   def definition
     # Optimize number of queries to the database by only looking up the actual
     # owner record for STI cases when the definition can't be found in the
@@ -58,9 +58,8 @@ class Preference &lt; ActiveRecord::Base
   alias_method_chain :group, :optional_lookup
   
   private
-    # Finds the definition for this preference's attribute in the given owner
-    # class.
+    # Finds the definition for this preference in the given owner class.
     def find_definition(owner_class)
-      owner_class.respond_to?(:preference_definitions) &amp;&amp; owner_class.preference_definitions[attribute]
+      owner_class.respond_to?(:preference_definitions) &amp;&amp; owner_class.preference_definitions[name]
     end
 end</diff>
      <filename>app/models/preference.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,13 @@
 class CreatePreferences &lt; ActiveRecord::Migration
   def self.up
     create_table :preferences do |t|
-      t.string :attribute, :null =&gt; false
+      t.string :name, :null =&gt; false
       t.references :owner, :polymorphic =&gt; true, :null =&gt; false
       t.references :group, :polymorphic =&gt; true
       t.string :value
       t.timestamps
     end
-    add_index :preferences, [:owner_id, :owner_type, :attribute, :group_id, :group_type], :unique =&gt; true, :name =&gt; 'index_preferences_on_owner_and_attribute_and_preference'
+    add_index :preferences, [:owner_id, :owner_type, :name, :group_id, :group_type], :unique =&gt; true, :name =&gt; 'index_preferences_on_owner_and_name_and_preference'
   end
   
   def self.down</diff>
      <filename>db/migrate/001_create_preferences.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,7 +23,7 @@ require 'preferences/preference_definition'
 # == Validations
 # 
 # Since the generated accessors for a preference allow the preference to be
-# treated just like regular ActiveRecord column attributes, they can also be
+# treated just like regular ActiveRecord attributes, they can also be
 # validated against in the same way.  For example,
 # 
 #   class User &lt; ActiveRecord::Base
@@ -76,8 +76,8 @@ module Preferences
     # 
     # == Generated accessors
     # 
-    # In addition to calling &lt;tt&gt;prefers?&lt;/tt&gt; and +preferred+ on a record, you
-    # can also use the shortcut accessor methods that are generated when a
+    # In addition to calling &lt;tt&gt;prefers?&lt;/tt&gt; and +preferred+ on a record,
+    # you can also use the shortcut accessor methods that are generated when a
     # preference is defined.  For example,
     # 
     #   class User &lt; ActiveRecord::Base
@@ -114,7 +114,7 @@ module Preferences
     #   user.preferred_color?(car)          # =&gt; true
     #   
     #   user.save!  # =&gt; true
-    def preference(attribute, *args)
+    def preference(name, *args)
       unless included_modules.include?(InstanceMethods)
         class_inheritable_hash :preference_definitions
         self.preference_definitions = {}
@@ -130,32 +130,32 @@ module Preferences
       end
       
       # Create the definition
-      attribute = attribute.to_s
-      definition = PreferenceDefinition.new(attribute, *args)
-      self.preference_definitions[attribute] = definition
-      self.default_preferences[attribute] = definition.default_value
+      name = name.to_s
+      definition = PreferenceDefinition.new(name, *args)
+      self.preference_definitions[name] = definition
+      self.default_preferences[name] = definition.default_value
       
-      # Create short-hand accessor methods, making sure that the attribute
+      # Create short-hand accessor methods, making sure that the name
       # is method-safe in terms of what characters are allowed
-      attribute = attribute.gsub(/[^A-Za-z0-9_-]/, '').underscore
+      name = name.gsub(/[^A-Za-z0-9_-]/, '').underscore
       
       # Query lookup
-      define_method(&quot;preferred_#{attribute}?&quot;) do |*group|
-        preferred?(attribute, group.first)
+      define_method(&quot;preferred_#{name}?&quot;) do |*group|
+        preferred?(name, group.first)
       end
-      alias_method &quot;prefers_#{attribute}?&quot;, &quot;preferred_#{attribute}?&quot;
+      alias_method &quot;prefers_#{name}?&quot;, &quot;preferred_#{name}?&quot;
       
       # Reader
-      define_method(&quot;preferred_#{attribute}&quot;) do |*group|
-        preferred(attribute, group.first)
+      define_method(&quot;preferred_#{name}&quot;) do |*group|
+        preferred(name, group.first)
       end
-      alias_method &quot;prefers_#{attribute}&quot;, &quot;preferred_#{attribute}&quot;
+      alias_method &quot;prefers_#{name}&quot;, &quot;preferred_#{name}&quot;
       
       # Writer
-      define_method(&quot;preferred_#{attribute}=&quot;) do |*args|
-        set_preference(*([attribute] + [args].flatten))
+      define_method(&quot;preferred_#{name}=&quot;) do |*args|
+        set_preference(*([name] + [args].flatten))
       end
-      alias_method &quot;prefers_#{attribute}=&quot;, &quot;preferred_#{attribute}=&quot;
+      alias_method &quot;prefers_#{name}=&quot;, &quot;preferred_#{name}=&quot;
       
       definition
     end
@@ -211,7 +211,7 @@ module Preferences
       # Find all of the stored preferences
       stored_preferences = self.stored_preferences.find(:all, :conditions =&gt; conditions)
       
-      # Hashify attribute -&gt; value or group -&gt; attribute -&gt; value
+      # Hashify name -&gt; value or group -&gt; name -&gt; value
       stored_preferences.inject(self.class.default_preferences.dup) do |all_preferences, preference|
         if !group &amp;&amp; (preference_group = preference.group)
           preferences = all_preferences[preference_group] ||= self.class.default_preferences.dup
@@ -219,13 +219,13 @@ module Preferences
           preferences = all_preferences
         end
         
-        preferences[preference.attribute] = preference.value
+        preferences[preference.name] = preference.value
         all_preferences
       end
     end
     
-    # Queries whether or not a value is present for the given attribute.  This
-    # is dependent on how the value is type-casted.
+    # Queries whether or not a value is present for the given preference.
+    # This is dependent on how the value is type-casted.
     # 
     # == Examples
     # 
@@ -242,15 +242,15 @@ module Preferences
     #   user.set_preference(:color, nil)
     #   user.preferred(:color)              # =&gt; nil
     #   user.preferred?(:color)             # =&gt; false
-    def preferred?(attribute, group = nil)
-      attribute = attribute.to_s
+    def preferred?(name, group = nil)
+      name = name.to_s
       
-      value = preferred(attribute, group)
-      preference_definitions[attribute].query(value)
+      value = preferred(name, group)
+      preference_definitions[name].query(value)
     end
     alias_method :prefers?, :preferred?
     
-    # Gets the actual value stored for the given attribute, or the default
+    # Gets the actual value stored for the given preference, or the default
     # value if nothing is present.
     # 
     # == Examples
@@ -266,27 +266,27 @@ module Preferences
     #   
     #   user.set_preference(:color, 'blue')
     #   user.preferred(:color)            # =&gt; &quot;blue&quot;
-    def preferred(attribute, group = nil)
-      attribute = attribute.to_s
+    def preferred(name, group = nil)
+      name = name.to_s
       
-      if @preference_values &amp;&amp; @preference_values[attribute] &amp;&amp; @preference_values[attribute].include?(group)
-        # Value for this attribute/group has been written, but not saved yet:
+      if @preference_values &amp;&amp; @preference_values[group] &amp;&amp; @preference_values[group].include?(name)
+        # Value for this group/name has been written, but not saved yet:
         # grab from the pending values
-        value = @preference_values[attribute][group]
+        value = @preference_values[group][name]
       else
         # Split the group being filtered
         group_id, group_type = Preference.split_group(group)
         
         # Grab the first preference; if it doesn't exist, use the default value
-        preference = stored_preferences.find(:first, :conditions =&gt; {:attribute =&gt; attribute, :group_id =&gt; group_id, :group_type =&gt; group_type})
-        value = preference ? preference.value : preference_definitions[attribute].default_value
+        preference = stored_preferences.find(:first, :conditions =&gt; {:name =&gt; name, :group_id =&gt; group_id, :group_type =&gt; group_type})
+        value = preference ? preference.value : preference_definitions[name].default_value
       end
       
       value
     end
     alias_method :prefers, :preferred
     
-    # Sets a new value for the given attribute.  The actual Preference record
+    # Sets a new value for the given preference.  The actual Preference record
     # is *not* created until this record is saved.  In this way, preferences
     # act *exactly* the same as attributes.  They can be written to and
     # validated against, but won't actually be written to the database until
@@ -300,12 +300,12 @@ module Preferences
     #   
     #   user.set_preference(:color, 'blue', Car.first)  # =&gt; &quot;blue&quot;
     #   user.save!
-    def set_preference(attribute, value, group = nil)
-      attribute = attribute.to_s
+    def set_preference(name, value, group = nil)
+      name = name.to_s
       
       @preference_values ||= {}
-      @preference_values[attribute] ||= {}
-      @preference_values[attribute][group] = value
+      @preference_values[group] ||= {}
+      @preference_values[group][name] = value
       
       value
     end
@@ -315,10 +315,11 @@ module Preferences
       # was last saved
       def update_preferences
         if @preference_values
-          @preference_values.each do |attribute, grouped_records|
-            grouped_records.each do |group, value|
-              group_id, group_type = Preference.split_group(group)
-              attributes = {:attribute =&gt; attribute, :group_id =&gt; group_id, :group_type =&gt; group_type}
+          @preference_values.each do |group, new_preferences|
+            group_id, group_type = Preference.split_group(group)
+            
+            new_preferences.each do |name, value|
+              attributes = {:name =&gt; name, :group_id =&gt; group_id, :group_type =&gt; group_type}
               
               # Find an existing preference or build a new one
               preference = stored_preferences.find(:first, :conditions =&gt; attributes) ||  stored_preferences.build(attributes)</diff>
      <filename>lib/preferences.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,23 +1,23 @@
 module Preferences
   # Represents the definition of a preference for a particular model
   class PreferenceDefinition
-    def initialize(attribute, *args) #:nodoc:
+    def initialize(name, *args) #:nodoc:
       options = args.extract_options!
       options.assert_valid_keys(:default)
       
       @type = args.first ? args.first.to_s : 'boolean'
       
       # Create a column that will be responsible for typecasting
-      @column = ActiveRecord::ConnectionAdapters::Column.new(attribute.to_s, options[:default], @type == 'any' ? nil : @type)
+      @column = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], @type == 'any' ? nil : @type)
     end
     
-    # The attribute which is being preferenced
-    def attribute
+    # The name of the preference
+    def name
       @column.name
     end
     
     # The default value to use for the preference in case none have been
-    # previously defined      
+    # previously defined
     def default_value
       @column.default
     end</diff>
      <filename>lib/preferences/preference_definition.rb</filename>
    </modified>
    <modified>
      <diff>@@ -52,7 +52,7 @@ module Factory
   build Preference do |attributes|
     attributes[:owner] = create_user unless attributes.include?(:owner)
     attributes.reverse_merge!(
-      :attribute =&gt; 'notifications',
+      :name =&gt; 'notifications',
       :value =&gt; false
     )
   end</diff>
      <filename>test/factory.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@ class PreferenceDefinitionByDefaultTest &lt; ActiveSupport::TestCase
     @definition = Preferences::PreferenceDefinition.new(:notifications)
   end
   
-  def test_should_have_an_attribute
-    assert_equal 'notifications', @definition.attribute
+  def test_should_have_a_name
+    assert_equal 'notifications', @definition.name
   end
   
   def test_should_not_have_a_default_value</diff>
      <filename>test/unit/preference_definition_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,8 +5,8 @@ class PreferenceByDefaultTest &lt; ActiveSupport::TestCase
     @preference = Preference.new
   end
   
-  def test_should_not_have_an_attribute
-    assert @preference.attribute.blank?
+  def test_should_not_have_a_name
+    assert @preference.name.blank?
   end
   
   def test_should_not_have_an_owner
@@ -40,10 +40,10 @@ class PreferenceTest &lt; ActiveSupport::TestCase
     assert preference.valid?
   end
   
-  def test_should_require_an_attribute
-    preference = new_preference(:attribute =&gt; nil)
+  def test_should_require_a_name
+    preference = new_preference(:name =&gt; nil)
     assert !preference.valid?
-    assert preference.errors.invalid?(:attribute)
+    assert preference.errors.invalid?(:name)
   end
   
   def test_should_require_an_owner_id
@@ -84,7 +84,7 @@ class PreferenceTest &lt; ActiveSupport::TestCase
   def test_should_protect_attributes_from_mass_assignment
     preference = Preference.new(
       :id =&gt; 1,
-      :attribute =&gt; 'notifications',
+      :name =&gt; 'notifications',
       :value =&gt; '123',
       :owner_id =&gt; 1,
       :owner_type =&gt; 'User',
@@ -93,7 +93,7 @@ class PreferenceTest &lt; ActiveSupport::TestCase
     )
     
     assert_nil preference.id
-    assert_equal 'notifications', preference.attribute
+    assert_equal 'notifications', preference.name
     assert_equal '123', preference.value
     assert_equal 1, preference.owner_id
     assert_equal 'User', preference.owner_type
@@ -132,7 +132,7 @@ class PreferenceAfterBeingCreatedTest &lt; ActiveSupport::TestCase
   def setup
     User.preference :notifications, :boolean
     
-    @preference = create_preference(:attribute =&gt; 'notifications')
+    @preference = create_preference(:name =&gt; 'notifications')
   end
   
   def test_should_have_an_owner
@@ -178,18 +178,18 @@ class PreferenceWithActiveRecordGroupTest &lt; ActiveSupport::TestCase
   end
 end
 
-class PreferenceWithBooleanAttributeTest &lt; ActiveSupport::TestCase
+class PreferenceWithBooleanTypeTest &lt; ActiveSupport::TestCase
   def setup
     User.preference :notifications, :boolean
   end
   
   def test_should_type_cast_nil_values
-    preference = new_preference(:attribute =&gt; 'notifications', :value =&gt; nil)
+    preference = new_preference(:name =&gt; 'notifications', :value =&gt; nil)
     assert_nil preference.value
   end
   
   def test_should_type_cast_numeric_values
-    preference = new_preference(:attribute =&gt; 'notifications', :value =&gt; 0)
+    preference = new_preference(:name =&gt; 'notifications', :value =&gt; 0)
     assert_equal false, preference.value
     
     preference.value = 1
@@ -197,7 +197,7 @@ class PreferenceWithBooleanAttributeTest &lt; ActiveSupport::TestCase
   end
   
   def test_should_type_cast_boolean_values
-    preference = new_preference(:attribute =&gt; 'notifications', :value =&gt; false)
+    preference = new_preference(:name =&gt; 'notifications', :value =&gt; false)
     assert_equal false, preference.value
     
     preference.value = true
@@ -213,7 +213,7 @@ end
 class PreferenceWithSTIOwnerTest &lt; ActiveSupport::TestCase
   def setup
     @manager = create_manager
-    @preference = create_preference(:owner =&gt; @manager, :attribute =&gt; 'health_insurance', :value =&gt; true)
+    @preference = create_preference(:owner =&gt; @manager, :name =&gt; 'health_insurance', :value =&gt; true)
   end
   
   def test_should_have_an_owner</diff>
      <filename>test/unit/preference_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ac011c4903c473a25ac90ee0f00a1f43b05cf68d</id>
    </parent>
  </parents>
  <author>
    <name>Aaron Pfeifer</name>
    <email>aaron.pfeifer@gmail.com</email>
  </author>
  <url>http://github.com/pluginaweek/preferences/commit/08cf4b9bddea8aac45c2c79215f1b1810d7dbf2e</url>
  <id>08cf4b9bddea8aac45c2c79215f1b1810d7dbf2e</id>
  <committed-date>2009-04-25T10:39:41-07:00</committed-date>
  <authored-date>2009-04-25T10:39:41-07:00</authored-date>
  <message>Rename Preference#attribute to #name to avoid conflicts with reserved methods in ActiveRecord</message>
  <tree>d1d377c0fc723554625c639f641b394ae4db2c11</tree>
  <committer>
    <name>Aaron Pfeifer</name>
    <email>aaron.pfeifer@gmail.com</email>
  </committer>
</commit>
