resort 0.2.0 → 0.2.1
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.
- data/lib/resort/version.rb +1 -1
- data/lib/resort.rb +29 -19
- data/spec/spec_helper.rb +4 -0
- metadata +3 -3
    
        data/lib/resort/version.rb
    CHANGED
    
    
    
        data/lib/resort.rb
    CHANGED
    
    | @@ -140,8 +140,11 @@ module Resort | |
| 140 140 | 
             
                  # in the first position. Otherwise, it appends it to the end of the
         | 
| 141 141 | 
             
                  # empty list.
         | 
| 142 142 | 
             
                  def include_in_list!
         | 
| 143 | 
            -
                     | 
| 144 | 
            -
             | 
| 143 | 
            +
                    self.class.transaction do
         | 
| 144 | 
            +
                      self.lock!
         | 
| 145 | 
            +
                      _siblings.count > 0 ? last!\
         | 
| 146 | 
            +
                                          : prepend
         | 
| 147 | 
            +
                    end
         | 
| 145 148 | 
             
                  end
         | 
| 146 149 |  | 
| 147 150 | 
             
                  # Puts the object in the first position of the list.
         | 
| @@ -149,8 +152,11 @@ module Resort | |
| 149 152 | 
             
                    return if first?
         | 
| 150 153 |  | 
| 151 154 | 
             
                    if _siblings.count > 0
         | 
| 152 | 
            -
                       | 
| 153 | 
            -
             | 
| 155 | 
            +
                      self.class.transaction do
         | 
| 156 | 
            +
                        self.lock!
         | 
| 157 | 
            +
                        delete_from_list
         | 
| 158 | 
            +
                        _siblings.where(:first => true).first.append_to(self)
         | 
| 159 | 
            +
                      end
         | 
| 154 160 | 
             
                    end
         | 
| 155 161 |  | 
| 156 162 | 
             
                    self.update_attribute(:first, true)
         | 
| @@ -158,16 +164,20 @@ module Resort | |
| 158 164 |  | 
| 159 165 | 
             
                  # Puts the object in the last position of the list.
         | 
| 160 166 | 
             
                  def push
         | 
| 161 | 
            -
                    self. | 
| 167 | 
            +
                    self.class.transaction do
         | 
| 168 | 
            +
                      self.lock!
         | 
| 169 | 
            +
                      self.append_to(_siblings.last_in_order) unless last?
         | 
| 170 | 
            +
                    end
         | 
| 162 171 | 
             
                  end
         | 
| 163 172 |  | 
| 164 173 | 
             
                  # Puts the object right after another object in the list.
         | 
| 165 174 | 
             
                  def append_to(another)
         | 
| 166 175 | 
             
                    return if another.next_id == id
         | 
| 167 176 |  | 
| 168 | 
            -
                    delete_from_list
         | 
| 169 | 
            -
             | 
| 170 177 | 
             
                    self.class.transaction do
         | 
| 178 | 
            +
                      self.lock!
         | 
| 179 | 
            +
                      another.lock!
         | 
| 180 | 
            +
                      delete_from_list
         | 
| 171 181 | 
             
                      self.update_attribute(:next_id, another.next_id) if self.next_id or (another && another.next_id)
         | 
| 172 182 | 
             
                      another.update_attribute(:next_id, self.id) if another
         | 
| 173 183 | 
             
                    end
         | 
| @@ -176,19 +186,19 @@ module Resort | |
| 176 186 | 
             
                  private
         | 
| 177 187 |  | 
| 178 188 | 
             
                  def delete_from_list
         | 
| 179 | 
            -
                    self. | 
| 180 | 
            -
                       | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
                       | 
| 189 | 
            +
                    if first? && self.next
         | 
| 190 | 
            +
                      self.next.lock!
         | 
| 191 | 
            +
                      self.next.update_attribute(:first, true)
         | 
| 192 | 
            +
                    elsif self.previous
         | 
| 193 | 
            +
                      self.previous.lock!
         | 
| 194 | 
            +
                      self.previous.update_attribute(:next_id, self.next_id)
         | 
| 195 | 
            +
                    end
         | 
| 185 196 |  | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 189 | 
            -
             | 
| 190 | 
            -
             | 
| 191 | 
            -
                      end
         | 
| 197 | 
            +
                    unless frozen?
         | 
| 198 | 
            +
                      self.first = false 
         | 
| 199 | 
            +
                      self.next = nil 
         | 
| 200 | 
            +
                      self.previous = nil 
         | 
| 201 | 
            +
                      save!
         | 
| 192 202 | 
             
                    end
         | 
| 193 203 | 
             
                  end
         | 
| 194 204 |  | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: resort
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.2. | 
| 5 | 
            +
              version: 0.2.1
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors: 
         | 
| 8 8 | 
             
            - Oriol Gual
         | 
| @@ -12,7 +12,7 @@ autorequire: | |
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 14 |  | 
| 15 | 
            -
            date: 2011- | 
| 15 | 
            +
            date: 2011-04-13 00:00:00 +02:00
         | 
| 16 16 | 
             
            default_executable: 
         | 
| 17 17 | 
             
            dependencies: 
         | 
| 18 18 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 130 130 | 
             
            requirements: []
         | 
| 131 131 |  | 
| 132 132 | 
             
            rubyforge_project: resort
         | 
| 133 | 
            -
            rubygems_version: 1.5. | 
| 133 | 
            +
            rubygems_version: 1.5.2
         | 
| 134 134 | 
             
            signing_key: 
         | 
| 135 135 | 
             
            specification_version: 3
         | 
| 136 136 | 
             
            summary: Positionless model sorting for Rails 3.
         |