mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Made the last tweaks before 0.9
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@197 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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 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 add_to_list_top
|
||||
increment_positions_on_all_items
|
||||
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 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 increment_positions_on_all_items
|
||||
self.class.update_all(
|
||||
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
|
||||
)
|
||||
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 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_all_items
|
||||
self.class.update_all(
|
||||
"#{position_column} = (#{position_column} + 1)", "#{scope_condition}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user