myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2729] trunk: removed write_once_of feature


From: noreply
Subject: [myexperiment-hackers] [2729] trunk: removed write_once_of feature
Date: Thu, 20 Oct 2011 18:35:26 -0400 (EDT)

Revision
2729
Author
dgc
Date
2011-10-20 18:35:26 -0400 (Thu, 20 Oct 2011)

Log Message

removed write_once_of feature

Modified Paths

Removed Paths

Diff

Modified: trunk/app/models/user.rb (2728 => 2729)


--- trunk/app/models/user.rb	2011-10-20 22:30:31 UTC (rev 2728)
+++ trunk/app/models/user.rb	2011-10-20 22:35:26 UTC (rev 2729)
@@ -9,8 +9,6 @@
 require 'acts_as_contributor'
 require 'acts_as_creditor'
 
-require 'write_once_of'
-
 class User < ActiveRecord::Base
   
   has_many :citations, 
@@ -127,8 +125,6 @@
                             :message => "can only contain characters, numbers and _",
                             :if => Proc.new { |user| !user.username.nil? }
                             
-  validates_write_once_of   :username, :on => :update, :if => Proc.new { |user| !user.username.nil? }, :message => "cannot be changed"  
-                          
   validates_presence_of     :openid_url, :if => Proc.new { |user| !user.openid_url.nil? }
   validates_uniqueness_of   :openid_url, :if => Proc.new { |user| !user.openid_url.nil? }
   

Deleted: trunk/lib/write_once_of.rb (2728 => 2729)


--- trunk/lib/write_once_of.rb	2011-10-20 22:30:31 UTC (rev 2728)
+++ trunk/lib/write_once_of.rb	2011-10-20 22:35:26 UTC (rev 2729)
@@ -1,23 +0,0 @@
-# Modified from: http://forums.pragprog.com/forums/8/topics/2
-
-module WriteOnceOf
-  def validates_write_once_of(*attr_names)
-    configuration = { :message => "can't be changed" }
-    configuration.merge!(attr_names.pop) if attr_names.last.is_a?(Hash)
-    send( validation_method(:update) ) do |record|
-      unless configuration[:if] and not evaluate_condition(configuration[:if], record)
-        previous = self.find record.id
-        attr_names.each do |attr_name|
-          # Updated from original [Jits, 2008-01-09]: added condition below, to allow attributes to be set at a later stage.
-          # So write once check is only done if the old value was not nil.
-          unless eval("previous.#{attr_name}.nil?")
-            record.errors.add( attr_name, configuration[:message] ) if record.respond_to?(attr_name) and previous.send(attr_name) != record.send(attr_name)
-            # replace the 'and' above with a double ampersand
-          end
-        end
-      end
-    end
-  end
-end
-
-ActiveRecord::Base.extend WriteOnceOf
\ No newline at end of file

reply via email to

[Prev in Thread] Current Thread [Next in Thread]