sortability 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/Rakefile +11 -7
- data/lib/sortability/active_record/base.rb +13 -13
- data/lib/sortability/active_record/connection_adapters/table_definition.rb +2 -2
- data/lib/sortability/active_record/migration.rb +4 -4
- data/lib/sortability/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/config/application.rb +2 -2
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +7050 -4006
- data/spec/lib/sortability/active_record/base_spec.rb +12 -18
- data/spec/lib/sortability/active_record/connection_adapters/table_definition_spec.rb +3 -3
- data/spec/lib/sortability/active_record/migration_spec.rb +4 -4
- data/spec/rails_helper.rb +0 -1
- metadata +52 -48
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -140
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 468cc73b34b9eeca08746606ce03659756b65e9743a2f94a84b3e91476684c3b
|
4
|
+
data.tar.gz: c351cb7e7185e39e2a40003d8e38a168bd09c7e7c85d24c15c54f164bacc82ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aad0bc50eb8804585962e1f713bbc3afdaad93c2f044a1dffb85a9d146f4ae082d57e94de16ae9a24a2d814174c80ba9eab360892b9103b2dbdf819f30bbe14
|
7
|
+
data.tar.gz: e4549124e9f4027510e7e034daa867c0362f1dcc9093bd40d25e474715746f371de7ffde0613b7b0c9e043c3ecc5c5641298596ab2fe3777bc51d06007b6a450
|
data/Rakefile
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
|
1
3
|
begin
|
2
4
|
require 'bundler/setup'
|
3
5
|
rescue LoadError
|
4
6
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
7
|
end
|
6
8
|
|
9
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
10
|
+
load 'rails/tasks/engine.rake'
|
11
|
+
|
7
12
|
Bundler::GemHelper.install_tasks
|
8
13
|
|
9
|
-
|
14
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |file| load file }
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
16
|
+
require 'rspec/core'
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
|
19
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
20
|
+
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
|
17
21
|
|
18
22
|
task default: :spec
|
@@ -8,7 +8,7 @@ module Sortability
|
|
8
8
|
module ClassMethods
|
9
9
|
# Defines methods that are used to sort records
|
10
10
|
# Use via sortable_belongs_to or sortable_class
|
11
|
-
def sortable_methods(options
|
11
|
+
def sortable_methods(**options)
|
12
12
|
on = options[:on] || :sort_position
|
13
13
|
container = options[:container]
|
14
14
|
inverse_of = options[:inverse_of]
|
@@ -126,24 +126,24 @@ module Sortability
|
|
126
126
|
end
|
127
127
|
|
128
128
|
# Defines a sortable has_many relation on the container
|
129
|
-
def sortable_has_many(records, scope_or_options = nil,
|
130
|
-
scope, options = extract_association_params(scope_or_options,
|
129
|
+
def sortable_has_many(records, scope_or_options = nil, **remaining_options, &extension)
|
130
|
+
scope, options = extract_association_params(scope_or_options, remaining_options)
|
131
131
|
if scope.nil?
|
132
132
|
on = options[:on] || :sort_position
|
133
133
|
scope = -> { order(on) }
|
134
134
|
end
|
135
135
|
|
136
|
-
class_exec { has_many records, scope, options.except(:on), &extension }
|
136
|
+
class_exec { has_many records, scope, **options.except(:on), &extension }
|
137
137
|
end
|
138
138
|
|
139
139
|
# Defines a sortable belongs_to relation on the child records
|
140
140
|
def sortable_belongs_to(container, scope_or_options = nil,
|
141
|
-
|
142
|
-
scope, options = extract_association_params(scope_or_options,
|
141
|
+
**remaining_options, &extension)
|
142
|
+
scope, options = extract_association_params(scope_or_options, remaining_options)
|
143
143
|
on = options[:on] || :sort_position
|
144
144
|
|
145
145
|
class_exec do
|
146
|
-
belongs_to container, scope, options.except(:on, :scope), &extension
|
146
|
+
belongs_to container, scope, **options.except(:on, :scope), &extension
|
147
147
|
|
148
148
|
reflection = reflect_on_association(container)
|
149
149
|
options[:scope] ||= reflection.polymorphic? ? \
|
@@ -159,11 +159,11 @@ module Sortability
|
|
159
159
|
end
|
160
160
|
|
161
161
|
options[:container] = container
|
162
|
-
sortable_methods(options)
|
162
|
+
sortable_methods(**options)
|
163
163
|
end
|
164
164
|
|
165
165
|
# Defines a sortable class without a container
|
166
|
-
def sortable_class(options
|
166
|
+
def sortable_class(**options)
|
167
167
|
on = options[:on] || :sort_position
|
168
168
|
scope = options[:scope]
|
169
169
|
|
@@ -176,16 +176,16 @@ module Sortability
|
|
176
176
|
uniqueness: (scope.nil? ? true : { scope: scope })
|
177
177
|
end
|
178
178
|
|
179
|
-
sortable_methods(options)
|
179
|
+
sortable_methods(**options)
|
180
180
|
end
|
181
181
|
|
182
182
|
protected
|
183
183
|
|
184
|
-
def extract_association_params(scope_or_options,
|
184
|
+
def extract_association_params(scope_or_options, remaining_options)
|
185
185
|
if scope_or_options.is_a?(Hash)
|
186
|
-
[nil, scope_or_options]
|
186
|
+
[nil, scope_or_options.merge(remaining_options)]
|
187
187
|
else
|
188
|
-
[scope_or_options,
|
188
|
+
[scope_or_options, remaining_options]
|
189
189
|
end
|
190
190
|
end
|
191
191
|
end
|
@@ -3,11 +3,11 @@ module Sortability
|
|
3
3
|
module ConnectionAdapters
|
4
4
|
module TableDefinition
|
5
5
|
# Adds a non-null sortable column on table creation (no index)
|
6
|
-
def sortable(options
|
6
|
+
def sortable(**options)
|
7
7
|
options[:null] = false if options[:null].nil?
|
8
8
|
on = options.delete(:on) || :sort_position
|
9
9
|
|
10
|
-
integer on, options
|
10
|
+
integer on, **options
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -2,21 +2,21 @@ module Sortability
|
|
2
2
|
module ActiveRecord
|
3
3
|
module Migration
|
4
4
|
# Adds a non-null sortable column to an existing table (no index)
|
5
|
-
def add_sortable_column(table, options
|
5
|
+
def add_sortable_column(table, **options)
|
6
6
|
options[:null] = false if options[:null].nil?
|
7
7
|
on = options.delete(:on) || :sort_position
|
8
8
|
|
9
|
-
add_column table, on, :integer, options
|
9
|
+
add_column table, on, :integer, **options
|
10
10
|
end
|
11
11
|
|
12
12
|
# Adds a unique index covering the sort scope cols in an existing table
|
13
|
-
def add_sortable_index(table, options
|
13
|
+
def add_sortable_index(table, **options)
|
14
14
|
options[:unique] = true if options[:unique].nil?
|
15
15
|
scope = options.delete(:scope)
|
16
16
|
on = options.delete(:on) || :sort_position
|
17
17
|
columns = ([scope] << on).flatten.compact
|
18
18
|
|
19
|
-
add_index table, columns, options
|
19
|
+
add_index table, columns, **options
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/sortability/version.rb
CHANGED
@@ -3,12 +3,12 @@ require File.expand_path('../boot', __FILE__)
|
|
3
3
|
require 'rails/all'
|
4
4
|
|
5
5
|
Bundler.require(*Rails.groups)
|
6
|
-
require
|
6
|
+
require 'sortability'
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
10
10
|
# Initialize configuration defaults for originally generated Rails version.
|
11
|
-
config.load_defaults
|
11
|
+
config.load_defaults 6.1
|
12
12
|
|
13
13
|
# Settings in config/environments/* take precedence over those specified here.
|
14
14
|
# Application configuration should go into files in config/initializers
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|