shuber-sortable 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/CHANGELOG +1 -0
  2. data/lib/sortable.rb +11 -8
  3. metadata +1 -1
data/CHANGELOG CHANGED
@@ -1,5 +1,6 @@
1
1
  2009-05-14 - Sean Huber (shuber@huberry.com)
2
2
  * Remove MIT-LICENSE from gemspec - github complaining for some reason
3
+ * Type cast position and offset arguments as integers
3
4
 
4
5
  2009-05-13 - Sean Huber (shuber@huberry.com)
5
6
  * Fix bug - item_at_offset method was not scoping correctly
data/lib/sortable.rb CHANGED
@@ -182,13 +182,16 @@ module Huberry
182
182
  #
183
183
  # Also aliased as <tt>insert_at_position!</tt>
184
184
  def insert_at!(position = 1, list_name = nil)
185
- remove_from_list!(list_name)
186
- if position > last_position(list_name)
187
- add_to_list!(list_name)
188
- else
189
- move_lower_items(:down, position - 1, list_name)
190
- send("#{evaluate_sortable_options(list_name)[:column]}=".to_sym, position)
191
- save
185
+ position = position.to_s.to_i
186
+ if position > 0
187
+ remove_from_list!(list_name)
188
+ if position > last_position(list_name)
189
+ add_to_list!(list_name)
190
+ else
191
+ move_lower_items(:down, position - 1, list_name)
192
+ send("#{evaluate_sortable_options(list_name)[:column]}=".to_sym, position)
193
+ save
194
+ end
192
195
  end
193
196
  end
194
197
  alias_method :insert_at_position!, :insert_at!
@@ -204,7 +207,7 @@ module Huberry
204
207
  # Returns nil if an item at the specified offset could not be found
205
208
  def item_at_offset(offset, list_name = nil)
206
209
  options = evaluate_sortable_options(list_name)
207
- in_list?(list_name) ? self.class.send("find_by_#{options[:column]}".to_sym, send(options[:column]) + offset, :conditions => options[:conditions]) : nil
210
+ in_list?(list_name) ? self.class.send("find_by_#{options[:column]}".to_sym, send(options[:column]) + offset.to_s.to_i, :conditions => options[:conditions]) : nil
208
211
  end
209
212
 
210
213
  # Returns the last item in a list associated with the current item
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuber-sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber