diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 19:43:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-16 19:43:27 +0000 |
commit | 2f3db152ecbb76c9bcb5b2e3aa12816896df79f1 (patch) | |
tree | dd2e7378ea09f1ba2ce124a3c7b24ca8c47ac01f /activerecord/lib | |
parent | b64c26ad9db0c85fc21c34dde28ba747552f05c9 (diff) | |
download | rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.tar.gz rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.tar.bz2 rails-2f3db152ecbb76c9bcb5b2e3aa12816896df79f1.zip |
Made the last tweaks before 0.9
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@197 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 115 | ||||
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 5 |
2 files changed, 60 insertions, 60 deletions
diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index bf4bd74597..626547f005 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -48,7 +48,7 @@ module ActiveRecord end before_destroy :remove_from_list - after_create :add_to_list_bottom + before_create :add_to_list_bottom EOV end end @@ -88,14 +88,6 @@ module ActiveRecord end - def add_to_list_top - increment_positions_on_all_items - end - - def add_to_list_bottom - assume_bottom_position - end - def remove_from_list decrement_positions_on_lower_items end @@ -119,58 +111,67 @@ module ActiveRecord end private - # Overwrite this method to define the scope of the list changes - def scope_condition() "1" end - - def higher_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" - ) - end + + def add_to_list_top + increment_positions_on_all_items + end + + def add_to_list_bottom + write_attribute(position_column, bottom_position_in_list.to_i + 1) + end + + # Overwrite this method to define the scope of the list changes + def scope_condition() "1" end + + def higher_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" + ) + end + + def lower_item + self.class.find_first( + "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" + ) + end + + def bottom_position_in_list + item = bottom_item + item ? item.send(position_column) : 0 + end + + def bottom_item + self.class.find_first( + "#{scope_condition} ", + "#{position_column} DESC" + ) + end + + def assume_bottom_position + update_attribute position_column, bottom_position_in_list.to_i + 1 + end - def lower_item - self.class.find_first( - "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" - ) - end + def assume_top_position + update_attribute position_column, 1 + end - def bottom_position_in_list - item = bottom_item - item ? item.send(position_column) : 0 - end + def decrement_positions_on_lower_items + self.class.update_all( + "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}" + ) + end - def bottom_item - self.class.find_first( - "#{scope_condition} ", - "#{position_column} DESC" - ) - end - - def assume_bottom_position - update_attribute position_column, bottom_position_in_list.to_i + 1 - end - - def assume_top_position - update_attribute position_column, 1 - end - - def decrement_positions_on_lower_items - self.class.update_all( - "#{position_column} = (#{position_column} - 1)", "#{scope_condition} AND #{position_column} > #{send(position_column).to_i}" - ) - end - - def increment_positions_on_higher_items - self.class.update_all( - "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column)}" - ) - end + def increment_positions_on_higher_items + self.class.update_all( + "#{position_column} = (#{position_column} + 1)", "#{scope_condition} AND #{position_column} < #{send(position_column)}" + ) + end - def increment_positions_on_all_items - self.class.update_all( - "#{position_column} = (#{position_column} + 1)", "#{scope_condition}" - ) - end + def increment_positions_on_all_items + self.class.update_all( + "#{position_column} = (#{position_column} + 1)", "#{scope_condition}" + ) + end end end end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 19a15c26e0..af3285f04e 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -190,7 +190,6 @@ module ActiveRecord class_eval(%(#{validation_method(configuration[:on])} %{errors.add( '#{attr_name}', '#{msg}') if #{attr_name}.to_s.length != #{is} })) end end - end # Validates whether the value of the specified attributes are unique across the system. Useful for making sure that only one user @@ -401,8 +400,8 @@ module ActiveRecord # If the length is above the boundary, the too_long_msg message will be used. If below, the too_short_msg. def add_on_boundary_breaking(attributes, range, too_long_msg = @@default_error_messages[:too_long], too_short_msg = @@default_error_messages[:too_short]) for attr in [attributes].flatten - add(attr, too_short_msg % range.begin) if @base.attribute_present?(attr.to_s) && @base.send(attr.to_s).length < range.begin - add(attr, too_long_msg % range.end) if @base.attribute_present?(attr.to_s) && @base.send(attr.to_s).length > range.end + add(attr, too_short_msg % range.begin) if @base[attr.to_s] && @base.send(attr.to_s).length < range.begin + add(attr, too_long_msg % range.end) if @base[attr.to_s] && @base.send(attr.to_s).length > range.end end end |