liszt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +10 -0
  2. data/.yardopts +1 -0
  3. data/Gemfile +7 -0
  4. data/Gemfile.lock +97 -0
  5. data/LICENSE +20 -0
  6. data/Rakefile +20 -0
  7. data/lib/liszt/instantizeable.rb +10 -0
  8. data/lib/liszt/list.rb +213 -0
  9. data/lib/liszt/version.rb +3 -0
  10. data/lib/liszt.rb +176 -0
  11. data/liszt.gemspec +24 -0
  12. data/test/dummy/Rakefile +7 -0
  13. data/test/dummy/app/assets/javascripts/application.js +7 -0
  14. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  15. data/test/dummy/app/controllers/application_controller.rb +3 -0
  16. data/test/dummy/app/helpers/application_helper.rb +2 -0
  17. data/test/dummy/app/mailers/.gitkeep +0 -0
  18. data/test/dummy/app/models/.gitkeep +0 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/config/application.rb +42 -0
  21. data/test/dummy/config/boot.rb +10 -0
  22. data/test/dummy/config/database.yml +25 -0
  23. data/test/dummy/config/environment.rb +5 -0
  24. data/test/dummy/config/environments/development.rb +27 -0
  25. data/test/dummy/config/environments/production.rb +51 -0
  26. data/test/dummy/config/environments/test.rb +39 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/inflections.rb +10 -0
  29. data/test/dummy/config/initializers/mime_types.rb +5 -0
  30. data/test/dummy/config/initializers/secret_token.rb +7 -0
  31. data/test/dummy/config/initializers/session_store.rb +8 -0
  32. data/test/dummy/config/initializers/wrap_parameters.rb +12 -0
  33. data/test/dummy/config/locales/en.yml +5 -0
  34. data/test/dummy/config/routes.rb +58 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/lib/assets/.gitkeep +0 -0
  37. data/test/dummy/log/.gitkeep +0 -0
  38. data/test/dummy/public/404.html +26 -0
  39. data/test/dummy/public/422.html +26 -0
  40. data/test/dummy/public/500.html +26 -0
  41. data/test/dummy/public/favicon.ico +0 -0
  42. data/test/dummy/script/rails +6 -0
  43. data/test/liszt_test.rb +7 -0
  44. data/test/test_helper.rb +10 -0
  45. metadata +167 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ doc/
5
+ test/dummy/db/*.sqlite3
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ .yardoc/
9
+ .rvmrc
10
+ /tags
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --private
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '3.1.0'
4
+ gem 'sqlite3'
5
+
6
+ # Specify your gem's dependencies in has_rank.gemspec
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ liszt (0.0.1)
5
+ redis
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.1.0)
11
+ actionpack (= 3.1.0)
12
+ mail (~> 2.3.0)
13
+ actionpack (3.1.0)
14
+ activemodel (= 3.1.0)
15
+ activesupport (= 3.1.0)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.2)
20
+ rack-cache (~> 1.0.3)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.0)
24
+ activemodel (3.1.0)
25
+ activesupport (= 3.1.0)
26
+ bcrypt-ruby (~> 3.0.0)
27
+ builder (~> 3.0.0)
28
+ i18n (~> 0.6)
29
+ activerecord (3.1.0)
30
+ activemodel (= 3.1.0)
31
+ activesupport (= 3.1.0)
32
+ arel (~> 2.2.1)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.1.0)
35
+ activemodel (= 3.1.0)
36
+ activesupport (= 3.1.0)
37
+ activesupport (3.1.0)
38
+ multi_json (~> 1.0)
39
+ arel (2.2.1)
40
+ bcrypt-ruby (3.0.1)
41
+ builder (3.0.0)
42
+ erubis (2.7.0)
43
+ hike (1.2.1)
44
+ i18n (0.6.0)
45
+ mail (2.3.0)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.16)
50
+ multi_json (1.0.3)
51
+ polyglot (0.3.2)
52
+ rack (1.3.3)
53
+ rack-cache (1.0.3)
54
+ rack (>= 0.4)
55
+ rack-mount (0.8.3)
56
+ rack (>= 1.0.0)
57
+ rack-ssl (1.3.2)
58
+ rack
59
+ rack-test (0.6.1)
60
+ rack (>= 1.0)
61
+ rails (3.1.0)
62
+ actionmailer (= 3.1.0)
63
+ actionpack (= 3.1.0)
64
+ activerecord (= 3.1.0)
65
+ activeresource (= 3.1.0)
66
+ activesupport (= 3.1.0)
67
+ bundler (~> 1.0)
68
+ railties (= 3.1.0)
69
+ railties (3.1.0)
70
+ actionpack (= 3.1.0)
71
+ activesupport (= 3.1.0)
72
+ rack-ssl (~> 1.3.2)
73
+ rake (>= 0.8.7)
74
+ rdoc (~> 3.4)
75
+ thor (~> 0.14.6)
76
+ rake (0.8.7)
77
+ rdoc (3.9.4)
78
+ redis (2.2.2)
79
+ sprockets (2.0.0)
80
+ hike (~> 1.2)
81
+ rack (~> 1.0)
82
+ tilt (!= 1.3.0, ~> 1.1)
83
+ sqlite3 (1.3.4)
84
+ thor (0.14.6)
85
+ tilt (1.3.3)
86
+ treetop (1.4.10)
87
+ polyglot
88
+ polyglot (>= 0.3.1)
89
+ tzinfo (0.3.29)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ liszt!
96
+ rails (= 3.1.0)
97
+ sqlite3
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Academia, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ begin
6
+ require 'yard'
7
+ YARD::Rake::YardocTask.new
8
+ rescue LoadError
9
+ end
10
+
11
+ require 'rake/testtask'
12
+
13
+ Rake::TestTask.new(:test) do |t|
14
+ t.libs << 'lib'
15
+ t.libs << 'test'
16
+ t.pattern = 'test/**/*_test.rb'
17
+ t.verbose = false
18
+ end
19
+
20
+ task :default => :test
@@ -0,0 +1,10 @@
1
+ module Liszt
2
+ module Instantizeable
3
+ def instantize(name)
4
+ klass = self
5
+ define_method(name) do |*args, &block|
6
+ klass.send(name, self, *args, &block)
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/liszt/list.rb ADDED
@@ -0,0 +1,213 @@
1
+ module Liszt
2
+ class List
3
+ # @param [String] key The Redis key associated with this list.
4
+ def initialize(key)
5
+ @key = key
6
+ end
7
+
8
+ # Remove existing list items and repopulate the list with the given ids
9
+ # (in the given order).
10
+ # @param [Array<Fixnum>] ids
11
+ # @return [Array<Fixnum>]
12
+ def clear_and_populate!(ids, &block)
13
+ redis.multi do
14
+ clear
15
+ # reverse and unshift to avoid touching the marker
16
+ ids.reverse.each { |id| unshift!(id) }
17
+ end
18
+ ids
19
+ end
20
+
21
+ # Has the list been initialized?
22
+ # @return [Boolean]
23
+ def initialized?
24
+ !length.nil?
25
+ end
26
+
27
+ # Does the list currently include this id?
28
+ # @param [Fixnum] id
29
+ # @return [Boolean]
30
+ def include?(id)
31
+ all.include?(id)
32
+ end
33
+
34
+ # Return the index of the given id in the list.
35
+ # @param [Fixnum] id
36
+ # @return [Fixnum]
37
+ def index(id)
38
+ all.index(id)
39
+ end
40
+
41
+ # Push the given id onto the top of the list, if not already present.
42
+ # @param [Fixnum] id
43
+ # @return [Boolean] <tt>false</tt> if the item was already in the list,
44
+ # <tt>true</tt> otherwise.
45
+ def unshift(id)
46
+ if include?(id)
47
+ false
48
+ else
49
+ unshift!(id)
50
+ true
51
+ end
52
+ end
53
+
54
+ # Push the given id onto the top of the list.
55
+ # @param [Fixnum] id
56
+ def unshift!(id)
57
+ redis.lpush(@key, id)
58
+ end
59
+
60
+ # Push the given id onto the bottom of the list, if not already present.
61
+ # @param [Fixnum] id
62
+ # @return [Boolean] <tt>false</tt> if the item was already in the list,
63
+ # <tt>true</tt> otherwise.
64
+ def push(id)
65
+ if include?(id)
66
+ false
67
+ else
68
+ push!(id)
69
+ true
70
+ end
71
+ end
72
+ alias << push
73
+
74
+ # Push the given id onto the bottom of the list.
75
+ # @param [Fixnum] id
76
+ def push!(id)
77
+ redis.rpop(@key)
78
+ redis.rpush(@key, id)
79
+ redis.rpush(@key, '*')
80
+ end
81
+
82
+ # Remove the given id from the list.
83
+ # @param [Fixnum] id
84
+ def remove(id)
85
+ redis.lrem(@key, 1, id)
86
+ end
87
+
88
+ # Clear all items from the list.
89
+ def clear
90
+ redis.del(@key)
91
+ redis.rpush(@key, '*')
92
+ end
93
+
94
+ # Return the number of ids in the list, or nil if it's uninitialized.
95
+ # @return [Fixnum]
96
+ # @return [nil]
97
+ def length
98
+ len = redis.llen(@key)
99
+ (len > 0) ? (len - 1) : nil
100
+ end
101
+
102
+ # Return an Array of all the ids in the list.
103
+ # @return [Array<Fixnum>]
104
+ def all
105
+ redis.lrange(@key, 0, -2).map(&:to_i)
106
+ end
107
+ alias to_a all
108
+
109
+ # Swap the position of the given id with the one above it. If it's at the
110
+ # top of the list or not present in the list, do nothing.
111
+ # @param [Fixnum] id
112
+ def move_up(id)
113
+ with_lock do
114
+ position = index(id)
115
+ if position.nil? or position == 0
116
+ nil
117
+ else
118
+ prev_id = get(position - 1)
119
+ redis.multi do
120
+ set(position - 1, id)
121
+ set(position, prev_id)
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ # Swap the position of the given id with the one below it. If it's at the
128
+ # bottom of the list or not present in the list, do nothing.
129
+ # @param [Fixnum] id
130
+ def move_down(id)
131
+ with_lock do
132
+ position = index(id)
133
+ if position.nil? or position == (length - 1)
134
+ nil
135
+ else
136
+ next_id = get(position + 1)
137
+ redis.multi do
138
+ set(position + 1, id)
139
+ set(position, next_id)
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ # Move the given id to the top of the list.
146
+ # @param [Fixnum] id
147
+ def move_to_top(id)
148
+ redis.multi do
149
+ remove(id)
150
+ unshift!(id)
151
+ end
152
+ end
153
+
154
+ # Move the given id to the bottom of the list.
155
+ # @param [Fixnum] id
156
+ def move_to_bottom(id)
157
+ redis.multi do
158
+ remove(id)
159
+ push!(id)
160
+ end
161
+ end
162
+
163
+ private
164
+ def redis
165
+ ::Liszt.redis
166
+ end
167
+
168
+ # Return the item at the given index in the list.
169
+ # @param [Fixnum] index
170
+ def get(index)
171
+ redis.lindex(@key, index).to_i
172
+ end
173
+
174
+ def set(index, value)
175
+ redis.lset(@key, index, value)
176
+ end
177
+
178
+ # Obtain an exclusive lock on the list, execute the given block, and then
179
+ # release the lock. If the lock is currently taken by someone else, we just
180
+ # block until it becomes available.
181
+ def with_lock
182
+ start_time = Time.now
183
+ until get_lock
184
+ sleep 0.25
185
+ raise "Timed out!" if (Time.now - start_time) > 2.0
186
+ end
187
+ yield
188
+ ensure
189
+ release_lock
190
+ end
191
+
192
+ def get_lock
193
+ if redis.setnx(lock_key, true)
194
+ redis.expire(lock_key, lock_expiration_time)
195
+ true
196
+ else
197
+ false
198
+ end
199
+ end
200
+
201
+ def release_lock
202
+ redis.del(lock_key)
203
+ end
204
+
205
+ def lock_key
206
+ "#{@key}:lock"
207
+ end
208
+
209
+ def lock_expiration_time
210
+ 5 # seconds
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,3 @@
1
+ module Liszt
2
+ VERSION = "0.0.1"
3
+ end
data/lib/liszt.rb ADDED
@@ -0,0 +1,176 @@
1
+ require "liszt/version"
2
+ require "liszt/instantizeable"
3
+ require "liszt/list"
4
+
5
+ module Liszt
6
+ mattr_accessor :redis
7
+
8
+ # Set up a scoped ordering for this model.
9
+ #
10
+ # Liszt currently only supports one type of ranking per model. It also doesn't
11
+ # currently support re-sorting lists when a scope changes. The assumption is
12
+ # that attributes used as scopes won't change after creation.
13
+ #
14
+ # @param [Hash] options
15
+ # @option options [Symbol, Array] :scope The attribute or attributes to use
16
+ # as list constraints.
17
+ # @option options [Hash] :conditions Any extra constraints to impose.
18
+ def acts_as_liszt(options = {})
19
+ extend Instantizeable
20
+ extend ClassMethods
21
+ include InstanceMethods
22
+
23
+ # Make "instantized" versions of the class methods.
24
+ ClassMethods.instance_methods.each do |method|
25
+ instantize method
26
+ end
27
+
28
+ options.reverse_merge! :conditions => {}, :scope => []
29
+
30
+ @liszt_conditions = options[:conditions]
31
+ @liszt_scope = Array(options[:scope]).sort
32
+ @liszt_query = nil
33
+ end
34
+
35
+ module ClassMethods
36
+ def initialize_list!(obj={}, &block)
37
+ objects = find(:all, :conditions => liszt_query(obj))
38
+
39
+ # If the caller provided a block, sort the objects by that block's
40
+ # output before populating the list with their ids. If not, put
41
+ # the objects in descending order by id.
42
+ ids = if block_given?
43
+ objects.sort_by(&block).map(&:id)
44
+ else
45
+ objects.map(&:id).sort.reverse
46
+ end
47
+
48
+ ordered_list(obj).clear_and_populate!(ids)
49
+ ids
50
+ end
51
+
52
+ def ordered_list(obj={})
53
+ Liszt::List.new(liszt_key(obj))
54
+ end
55
+
56
+ def ordered_list_initialized?(obj={})
57
+ ordered_list(obj).initialized?
58
+ end
59
+
60
+ def ordered_list_ids(obj={})
61
+ return nil unless ordered_list_initialized?(obj)
62
+ ordered_list(obj).all
63
+ end
64
+
65
+ def ordered_list_items(obj={}, double_check=false)
66
+ return nil unless ordered_list_initialized?(obj)
67
+ ids = ordered_list_ids(obj)
68
+
69
+ if double_check
70
+ objs = find(:all, :conditions => liszt_query(obj))
71
+ real_ids = objs.map(&:id)
72
+ if real_ids != ids
73
+ unlisted_ids = real_ids - ids
74
+ ids = ordered_list(obj).clear_and_populate!(unlisted_ids + ids)
75
+ end
76
+ else
77
+ objs = find_all_by_id(ids)
78
+ end
79
+
80
+ objs.sort_by { |obj| ids.index(obj.id) }
81
+ end
82
+
83
+ def clear_list(obj={})
84
+ ordered_list(obj).clear
85
+ end
86
+
87
+ def meets_list_conditions?(obj={})
88
+ @liszt_conditions.all? { |key, value| obj[key] == value }
89
+ end
90
+
91
+ private
92
+ # Return the key for the Redis list that includes the given object.
93
+ def liszt_key(obj={})
94
+ key = "liszt:#{table_name}"
95
+ @liszt_scope.each do |scope|
96
+ key << ":#{scope}:#{obj[scope]}"
97
+ end
98
+ key
99
+ end
100
+
101
+ # Return the query that retrieves objects eligible to be
102
+ # in the list that includes the given object.
103
+ def liszt_query(obj={})
104
+ if @liszt_query.nil?
105
+ query = ['1 = 1']
106
+
107
+ @liszt_conditions.each do |key, value|
108
+ query.first << " AND (#{table_name}.#{key} "
109
+ if value.nil?
110
+ query.first << "IS NULL)"
111
+ else
112
+ query.first << "= ?)"
113
+ query << value
114
+ end
115
+ end
116
+
117
+ @liszt_scope.each do |scope|
118
+ query.first << " AND (#{table_name}.#{scope} = ?)"
119
+ end
120
+
121
+ @liszt_query = query
122
+ end
123
+
124
+ @liszt_query + @liszt_scope.map { |scope| obj[scope] }
125
+ end
126
+ end
127
+
128
+ module InstanceMethods
129
+ def self.included(base)
130
+ base.class_eval do
131
+ after_create :add_to_list
132
+ after_update :update_list
133
+ after_destroy :remove_from_list
134
+ end
135
+ end
136
+
137
+ def add_to_list
138
+ if meets_list_conditions?
139
+ ordered_list.unshift(self)
140
+ end
141
+ true
142
+ end
143
+
144
+ def update_list
145
+ if meets_list_conditions?
146
+ add_to_list
147
+ else
148
+ remove_from_list
149
+ end
150
+ true
151
+ end
152
+
153
+ def remove_from_list
154
+ ordered_list.remove(self.id)
155
+ true
156
+ end
157
+
158
+ def move_to_top!
159
+ ordered_list.move_to_top(self.id)
160
+ end
161
+
162
+ def move_up!
163
+ ordered_list.move_up(self.id)
164
+ end
165
+
166
+ def move_down!
167
+ ordered_list.move_down(self.id)
168
+ end
169
+
170
+ def move_to_bottom!
171
+ ordered_list.move_to_bottom(self.id)
172
+ end
173
+ end
174
+ end
175
+
176
+ ActiveRecord::Base.extend Liszt
data/liszt.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "liszt/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "liszt"
7
+ s.version = Liszt::VERSION
8
+ s.authors = ['Ryan Fitzgerald']
9
+ s.email = %w{rfitz@academia.edu}
10
+ s.homepage = "http://academia.edu"
11
+ s.summary = %q{ActiveRecord sorting using Redis lists}
12
+ s.description = %q{Liszt is an alternative to acts_as_list and sortable that uses atomic Redis operations to maintain scoped ordering information for ActiveRecord objects.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = %w{lib}
18
+
19
+ s.add_runtime_dependency 'rails', '>= 2.3.2'
20
+ s.add_runtime_dependency 'redis'
21
+
22
+ s.add_development_dependency 'yard'
23
+ s.add_development_dependency 'rdiscount'
24
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,7 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require
6
+ require "liszt"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Custom directories with classes and modules you want to be autoloadable.
15
+ # config.autoload_paths += %W(#{config.root}/extras)
16
+
17
+ # Only load the plugins named here, in the order given (default is alphabetical).
18
+ # :all can be used as a placeholder for all plugins not explicitly named.
19
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
+
21
+ # Activate observers that should always be running.
22
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Configure the default encoding used in templates for Ruby 1.9.
33
+ config.encoding = "utf-8"
34
+
35
+ # Configure sensitive parameters which will be filtered from the log file.
36
+ config.filter_parameters += [:password]
37
+
38
+ # Enable the asset pipeline
39
+ config.assets.enabled = true
40
+ end
41
+ end
42
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,27 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not compress assets
26
+ config.assets.compress = false
27
+ end
@@ -0,0 +1,51 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Specifies the header that your server uses for sending files
18
+ # (comment out if your front-end server doesn't support this)
19
+ config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
20
+
21
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
22
+ # config.force_ssl = true
23
+
24
+ # See everything in the log (default is :info)
25
+ # config.log_level = :debug
26
+
27
+ # Use a different logger for distributed setups
28
+ # config.logger = SyslogLogger.new
29
+
30
+ # Use a different cache store in production
31
+ # config.cache_store = :mem_cache_store
32
+
33
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
34
+ # config.action_controller.asset_host = "http://assets.example.com"
35
+
36
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
37
+ # config.assets.precompile += %w( search.js )
38
+
39
+ # Disable delivery errors, bad email addresses will be ignored
40
+ # config.action_mailer.raise_delivery_errors = false
41
+
42
+ # Enable threaded mode
43
+ # config.threadsafe!
44
+
45
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
46
+ # the I18n.default_locale when a translation can not be found)
47
+ config.i18n.fallbacks = true
48
+
49
+ # Send deprecation notices to registered listeners
50
+ config.active_support.deprecation = :notify
51
+ end
@@ -0,0 +1,39 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
33
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
34
+ # like if you have constraints or database-specific column types
35
+ # config.active_record.schema_format = :sql
36
+
37
+ # Print deprecation notices to the stderr
38
+ config.active_support.deprecation = :stderr
39
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'ae70f38c5073c3f0c514db85428bc8b9a46ba0fdc3a032fd4e9680164ac330845749327999adbad33b8457a40ee5965ee0a529dec067e36ea68857b91b8ce454'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActionController::Base.wrap_parameters format: [:json]
8
+
9
+ # Disable root element in JSON by default.
10
+ if defined?(ActiveRecord)
11
+ ActiveRecord::Base.include_root_in_json = false
12
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => 'welcome#index'
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
File without changes
File without changes
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class LisztTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Liszt
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liszt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Fitzgerald
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70276151086120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70276151086120
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis
27
+ requirement: &70276151085700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70276151085700
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70276151085240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70276151085240
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdiscount
49
+ requirement: &70276151084820 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70276151084820
58
+ description: Liszt is an alternative to acts_as_list and sortable that uses atomic
59
+ Redis operations to maintain scoped ordering information for ActiveRecord objects.
60
+ email:
61
+ - rfitz@academia.edu
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .yardopts
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE
71
+ - Rakefile
72
+ - lib/liszt.rb
73
+ - lib/liszt/instantizeable.rb
74
+ - lib/liszt/list.rb
75
+ - lib/liszt/version.rb
76
+ - liszt.gemspec
77
+ - test/dummy/Rakefile
78
+ - test/dummy/app/assets/javascripts/application.js
79
+ - test/dummy/app/assets/stylesheets/application.css
80
+ - test/dummy/app/controllers/application_controller.rb
81
+ - test/dummy/app/helpers/application_helper.rb
82
+ - test/dummy/app/mailers/.gitkeep
83
+ - test/dummy/app/models/.gitkeep
84
+ - test/dummy/app/views/layouts/application.html.erb
85
+ - test/dummy/config.ru
86
+ - test/dummy/config/application.rb
87
+ - test/dummy/config/boot.rb
88
+ - test/dummy/config/database.yml
89
+ - test/dummy/config/environment.rb
90
+ - test/dummy/config/environments/development.rb
91
+ - test/dummy/config/environments/production.rb
92
+ - test/dummy/config/environments/test.rb
93
+ - test/dummy/config/initializers/backtrace_silencers.rb
94
+ - test/dummy/config/initializers/inflections.rb
95
+ - test/dummy/config/initializers/mime_types.rb
96
+ - test/dummy/config/initializers/secret_token.rb
97
+ - test/dummy/config/initializers/session_store.rb
98
+ - test/dummy/config/initializers/wrap_parameters.rb
99
+ - test/dummy/config/locales/en.yml
100
+ - test/dummy/config/routes.rb
101
+ - test/dummy/lib/assets/.gitkeep
102
+ - test/dummy/log/.gitkeep
103
+ - test/dummy/public/404.html
104
+ - test/dummy/public/422.html
105
+ - test/dummy/public/500.html
106
+ - test/dummy/public/favicon.ico
107
+ - test/dummy/script/rails
108
+ - test/liszt_test.rb
109
+ - test/test_helper.rb
110
+ homepage: http://academia.edu
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.6
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: ActiveRecord sorting using Redis lists
134
+ test_files:
135
+ - test/dummy/Rakefile
136
+ - test/dummy/app/assets/javascripts/application.js
137
+ - test/dummy/app/assets/stylesheets/application.css
138
+ - test/dummy/app/controllers/application_controller.rb
139
+ - test/dummy/app/helpers/application_helper.rb
140
+ - test/dummy/app/mailers/.gitkeep
141
+ - test/dummy/app/models/.gitkeep
142
+ - test/dummy/app/views/layouts/application.html.erb
143
+ - test/dummy/config.ru
144
+ - test/dummy/config/application.rb
145
+ - test/dummy/config/boot.rb
146
+ - test/dummy/config/database.yml
147
+ - test/dummy/config/environment.rb
148
+ - test/dummy/config/environments/development.rb
149
+ - test/dummy/config/environments/production.rb
150
+ - test/dummy/config/environments/test.rb
151
+ - test/dummy/config/initializers/backtrace_silencers.rb
152
+ - test/dummy/config/initializers/inflections.rb
153
+ - test/dummy/config/initializers/mime_types.rb
154
+ - test/dummy/config/initializers/secret_token.rb
155
+ - test/dummy/config/initializers/session_store.rb
156
+ - test/dummy/config/initializers/wrap_parameters.rb
157
+ - test/dummy/config/locales/en.yml
158
+ - test/dummy/config/routes.rb
159
+ - test/dummy/lib/assets/.gitkeep
160
+ - test/dummy/log/.gitkeep
161
+ - test/dummy/public/404.html
162
+ - test/dummy/public/422.html
163
+ - test/dummy/public/500.html
164
+ - test/dummy/public/favicon.ico
165
+ - test/dummy/script/rails
166
+ - test/liszt_test.rb
167
+ - test/test_helper.rb