Skip to content

Commit 0442e65

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Conflicts: lib/acts_as_list/active_record/acts/list.rb test/list_test.rb
2 parents 8a2e550 + 2adc513 commit 0442e65

21 files changed

+1475
-716
lines changed

.gemtest

Whitespace-only changes.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.gem
2+
.bundle
3+
Gemfile.lock
4+
pkg/*
5+
.rvmrc
6+
*.tmproj

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: ruby
2+
rvm:
3+
- 1.8.7
4+
- 1.9.2
5+
- 1.9.3

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "http://rubygems.org"
2+
3+
# Specify your gem's dependencies in acts_as_list-rails3.gemspec
4+
gemspec
5+
6+
gem 'rake'

README

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# ActsAsList
2+
3+
## Description
4+
5+
This `acts_as` extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a `position` column defined as an integer on the mapped database table.
6+
7+
## Installation
8+
9+
In your Gemfile:
10+
11+
gem 'acts_as_list'
12+
13+
Or, from the command line:
14+
15+
gem install acts_as_list
16+
17+
## Example
18+
19+
```ruby
20+
class TodoList < ActiveRecord::Base
21+
has_many :todo_items, :order => "position"
22+
end
23+
24+
class TodoItem < ActiveRecord::Base
25+
belongs_to :todo_list
26+
acts_as_list :scope => :todo_list
27+
end
28+
29+
todo_list.first.move_to_bottom
30+
todo_list.last.move_higher
31+
```
32+
33+
## Instance Methods Added To ActiveRecord Models
34+
35+
You'll have a number of methods added to each instance of the ActiveRecord model that to which `acts_as_list` is added.
36+
37+
In `acts_as_list`, "higher" means further up the list (a lower `position`), and "lower" means further down the list (a higher `position`). That can be confusing, so it might make sense to add tests that validate that you're using the right method given your context.
38+
39+
### Methods That Change Position and Reorder List
40+
41+
- `list_item.insert_at(2)`
42+
- `list_item.move_lower` will do nothing if the item is the lowest item
43+
- `list_item.move_higher` will do nothing if the item is the highest item
44+
- `list_item.move_to_bottom`
45+
- `list_item.move_to_top`
46+
- `list_item.remove_from_list`
47+
48+
### Methods That Change Position Without Reordering List
49+
50+
- `list_item.increment_position`
51+
- `list_item.decrement_position`
52+
- `list_item.set_list_position(3)`
53+
54+
### Methods That Return Attributes of the Item's List Position
55+
- `list_item.first?`
56+
- `list_item.last?`
57+
- `list_item.in_list?`
58+
- `list_item.not_in_list?`
59+
- `list_item.default_position?`
60+
- `list_item.higher_item`
61+
- `list_item.lower_item`
62+
63+
## Notes
64+
If the `position` column has a default value, then there is a slight change in behavior, i.e if you have 4 items in the list, and you insert 1, with a default position 0, it would be pushed to the bottom of the list. Please look at the tests for this and some recent pull requests for discussions related to this.
65+
66+
All `position` queries (select, update, etc.) inside gem methods are executed without the default scope (i.e. `Model.unscoped`), this will prevent nasty issues when the default scope is different from `acts_as_list` scope.
67+
68+
The `position` column is set after validations are called, so you should not put a `presence` validation on the `position` column.
69+
70+
## Versions
71+
All versions `0.1.5` onwards require Rails 3.0.x and higher.
72+
73+
## Build Status
74+
[![Build Status](https://secure.travis-ci.org/swanandp/acts_as_list.png)](https://secure.travis-ci.org/swanandp/acts_as_list)
75+
76+
## Roadmap
77+
78+
1. Sort based feature
79+
2. Rails 4 compatibility and bye bye Rails 2! Older versions would of course continue to work with Rails 2, but there won't be any support on those.
80+
81+
## Contributing to `acts_as_list`
82+
83+
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
84+
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
85+
- Fork the project
86+
- Start a feature/bugfix branch
87+
- Commit and push until you are happy with your contribution
88+
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
89+
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
90+
- I would recommend using Rails 3.1.x and higher for testing the build before a pull request. The current test harness does not quite work with 3.0.x. The plugin itself works, but the issue lies with testing infrastructure.
91+
92+
## Copyright
93+
94+
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license

Rakefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
require 'rake'
1+
require 'bundler'
2+
Bundler::GemHelper.install_tasks
3+
4+
#require 'rake'
25
require 'rake/testtask'
36

7+
# Run the test with 'rake' or 'rake test'
48
desc 'Default: run acts_as_list unit tests.'
59
task :default => :test
610

7-
desc 'Test the acts_as_ordered_tree plugin.'
11+
desc 'Test the acts_as_list plugin.'
812
Rake::TestTask.new(:test) do |t|
9-
t.libs << 'lib'
10-
t.pattern = 'test/**/*_test.rb'
11-
t.verbose = true
13+
t.libs << 'lib' << 'test'
14+
t.pattern = 'test/**/test_*.rb'
15+
t.verbose = false
1216
end
17+
18+
# Run the rdoc task to generate rdocs for this gem
19+
require 'rdoc/task'
20+
RDoc::Task.new do |rdoc|
21+
require "acts_as_list/version"
22+
version = ActiveRecord::Acts::List::VERSION
23+
24+
rdoc.rdoc_dir = 'rdoc'
25+
rdoc.title = "acts_as_list-rails3 #{version}"
26+
rdoc.rdoc_files.include('README*')
27+
rdoc.rdoc_files.include('lib/**/*.rb')
28+
end
29+

acts_as_list.gemspec

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- encoding: utf-8 -*-
2+
$:.push File.expand_path('../lib', __FILE__)
3+
require 'acts_as_list/version'
4+
5+
Gem::Specification.new do |s|
6+
7+
# Description Meta...
8+
s.name = 'acts_as_list'
9+
s.version = ActiveRecord::Acts::List::VERSION
10+
s.platform = Gem::Platform::RUBY
11+
s.authors = ['David Heinemeier Hansson', 'Swanand Pagnis', 'Quinn Chaffee']
12+
s.email = ['swanand.pagnis@gmail.com']
13+
s.homepage = 'https://github.com/swanandp/acts_as_list'
14+
s.summary = %q{A gem allowing a active_record model to act_as_list.}
15+
s.description = %q{This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.}
16+
s.rubyforge_project = 'acts_as_list'
17+
18+
19+
# Load Paths...
20+
s.files = `git ls-files`.split("\n")
21+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23+
s.require_paths = ['lib']
24+
25+
26+
# Dependencies (installed via 'bundle install')...
27+
s.add_development_dependency("bundler", [">= 1.0.0"])
28+
s.add_development_dependency("activerecord", [">= 1.15.4.7794"])
29+
s.add_development_dependency("rdoc")
30+
s.add_development_dependency("sqlite3")
31+
end

init.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
$:.unshift "#{File.dirname(__FILE__)}/lib"
2-
require 'active_record/acts/list'
3-
ActiveRecord::Base.class_eval { include ActiveRecord::Acts::List }
2+
require 'acts_as_list'
3+
4+
ActsAsList::Railtie.insert

lib/acts_as_list.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'acts_as_list/active_record/acts/list'
2+
3+
module ActsAsList
4+
if defined? Rails::Railtie
5+
require 'rails'
6+
class Railtie < Rails::Railtie
7+
initializer 'acts_as_list.insert_into_active_record' do
8+
ActiveSupport.on_load :active_record do
9+
ActsAsList::Railtie.insert
10+
end
11+
end
12+
end
13+
end
14+
15+
class Railtie
16+
def self.insert
17+
if defined?(ActiveRecord)
18+
ActiveRecord::Base.send(:include, ActiveRecord::Acts::List)
19+
end
20+
end
21+
end
22+
end
23+
24+
ActsAsList::Railtie.insert

0 commit comments

Comments
 (0)