acts_as_list 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9d85921cd5b149fa3581d5868734c62fb42e449e4058db26cffb0e62a146b9c
4
- data.tar.gz: 94b6b6a6599ec0fa381f737bd5b2132258b7620905016bb467e1663f9552021a
3
+ metadata.gz: af90a91e87476f41d5712ba02b1e409558b4b96e1a8ad4c448a18c21f6a39d88
4
+ data.tar.gz: 8441f44a8ad1e71639a29dc6e11477b728a0d8dbbe78d6d1e93d465ef7384697
5
5
  SHA512:
6
- metadata.gz: f991880d1399bdbe56e4ef2511368115fc382dfebe2549188e0b8123f5cd8a93b33f067a602aadd8dbfa70893662b6fe5072d9deea7aba26d8827b83b9e1ac41
7
- data.tar.gz: df1570e602643b91b602ed3044c9fbe8457ce95e42cf8fdca5858d8bd1460f4105f8839bf87c5338cb0fb4cbac11c46b15c6206dc039cc39cc3c1b561129fcee
6
+ metadata.gz: 15add9a3324c4a2aa8e03de8bae61be55e05362a65eac09fbd9f3d0924d8e79f7ebdbbb2bcff98cdec58830c041831385c2b5795c4f5857e1c220fc4aec49c1b
7
+ data.tar.gz: c57ac0454483abbe36e2c37dfb63525c40254f4f419a11367356a505df611d49cc55b422143a30bdbe624788e785d24f1effd6b9b4478d5c8293373e61292056
data/CHANGELOG.md CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## v1.2.3 - 2024-10-14
10
+
11
+ ### Changed
12
+ - Use `.with_connection do |connection|` where possible instead of `.connection` [\#441](https://github.com/brendon/acts_as_list/pull/441) ([flood4life])
13
+
14
+ ## v1.2.2 - 2024-07-16
15
+
16
+ ### Fixed
17
+ - Updated .gemspec to exclude unnecessary files from the gem package. [\#437](https://github.com/brendon/acts_as_list/pull/437) ([f440])
18
+
9
19
  ## v1.2.1 - 2024-06-06
10
20
 
11
21
  ### Fixed
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './with_connection'
4
+
3
5
  module ActiveRecord
4
6
  module Acts #:nodoc:
5
7
  module List #:nodoc:
@@ -459,7 +461,9 @@ module ActiveRecord
459
461
 
460
462
  # When using raw column name it must be quoted otherwise it can raise syntax errors with SQL keywords (e.g. order)
461
463
  def quoted_position_column
462
- @_quoted_position_column ||= self.class.connection.quote_column_name(position_column)
464
+ @_quoted_position_column ||= ActiveRecord::Acts::List::WithConnection.new(self.class).call do |connection|
465
+ connection.quote_column_name(position_column)
466
+ end
463
467
  end
464
468
 
465
469
  # Used in order clauses
@@ -481,9 +485,8 @@ module ActiveRecord
481
485
  requirement.satisfied_by?(version)
482
486
  end
483
487
 
484
- def primary_key_condition(id = nil)
485
- primary_keys = Array.wrap(self.class.primary_key)
486
- id ? primary_keys.zip(Array.wrap(id)).to_h : slice(*primary_keys)
488
+ def primary_key_condition(id = self.id)
489
+ { self.class.primary_key => [id] }
487
490
  end
488
491
  end
489
492
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './with_connection'
4
+
3
5
  module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
4
6
  def self.call(caller_class, position_column, touch_on_update)
5
7
  define_class_methods(caller_class, position_column, touch_on_update)
@@ -15,7 +17,9 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
15
17
  def self.define_class_methods(caller_class, position_column, touch_on_update)
16
18
  caller_class.class_eval do
17
19
  define_singleton_method :quoted_position_column do
18
- @_quoted_position_column ||= connection.quote_column_name(position_column)
20
+ @_quoted_position_column ||= ActiveRecord::Acts::List::WithConnection.new(self).call do |connection|
21
+ connection.quote_column_name(position_column)
22
+ end
19
23
  end
20
24
 
21
25
  define_singleton_method :quoted_position_column_with_table_name do
@@ -72,18 +76,22 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
72
76
  cached_quoted_now = quoted_current_time_from_proper_timezone
73
77
 
74
78
  timestamp_attributes_for_update_in_model.map do |attr|
75
- ", #{self.class.connection.quote_column_name(attr)} = #{cached_quoted_now}"
79
+ ActiveRecord::Acts::List::WithConnection.new(self.class).call do |connection|
80
+ ", #{connection.quote_column_name(attr)} = #{cached_quoted_now}"
81
+ end
76
82
  end.join
77
83
  end
78
84
 
79
85
  private
80
86
 
81
87
  def quoted_current_time_from_proper_timezone
82
- self.class.connection.quote(
83
- self.class.connection.quoted_date(
84
- current_time_from_proper_timezone
88
+ ActiveRecord::Acts::List::WithConnection.new(self.class).call do |connection|
89
+ connection.quote(
90
+ connection.quoted_date(
91
+ current_time_from_proper_timezone
92
+ )
85
93
  )
86
- )
94
+ end
87
95
  end
88
96
  end
89
97
  end
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './with_connection'
4
+
3
5
  module ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner #:nodoc:
4
6
  def self.call(caller_class, column, sequential_updates_option)
5
7
  caller_class.class_eval do
6
8
  define_method :sequential_updates? do
7
- if !defined?(@sequential_updates)
8
- if sequential_updates_option.nil?
9
- table_exists =
10
- if active_record_version_is?('>= 5')
11
- caller_class.connection.data_source_exists?(caller_class.table_name)
12
- else
13
- caller_class.connection.table_exists?(caller_class.table_name)
14
- end
15
- index_exists = caller_class.connection.index_exists?(caller_class.table_name, column, unique: true)
16
- @sequential_updates = table_exists && index_exists
17
- else
18
- @sequential_updates = sequential_updates_option
19
- end
20
- else
21
- @sequential_updates
9
+ return @sequential_updates if defined?(@sequential_updates)
10
+
11
+ return @sequential_updates = sequential_updates_option unless sequential_updates_option.nil?
12
+
13
+ ActiveRecord::Acts::List::WithConnection.new(caller_class).call do |connection|
14
+ table_exists =
15
+ if active_record_version_is?('>= 5')
16
+ connection.data_source_exists?(caller_class.table_name)
17
+ else
18
+ connection.table_exists?(caller_class.table_name)
19
+ end
20
+ index_exists = connection.index_exists?(caller_class.table_name, column, unique: true)
21
+ @sequential_updates = table_exists && index_exists
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module Acts
5
+ module List
6
+ class WithConnection
7
+ def initialize(recipient)
8
+ @recipient = recipient
9
+ end
10
+
11
+ attr_reader :recipient
12
+
13
+ def call
14
+ if recipient.respond_to?(:with_connection)
15
+ recipient.with_connection do |connection|
16
+ yield connection
17
+ end
18
+ else
19
+ yield recipient.connection
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Acts
5
5
  module List
6
- VERSION = '1.2.1'
6
+ VERSION = '1.2.3'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swanand Pagnis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-06-05 00:00:00.000000000 Z
12
+ date: 2024-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -134,16 +134,10 @@ extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
136
  - ".gemtest"
137
- - ".github/FUNDING.yml"
138
- - ".github/dependabot.yml"
139
- - ".github/workflows/continuous_integration.yml"
140
- - ".gitignore"
141
137
  - CHANGELOG.md
142
- - Gemfile
143
138
  - MIT-LICENSE
144
139
  - README.md
145
140
  - Rakefile
146
- - acts_as_list.gemspec
147
141
  - init.rb
148
142
  - lib/acts_as_list.rb
149
143
  - lib/acts_as_list/active_record/acts/active_record.rb
@@ -156,25 +150,8 @@ files:
156
150
  - lib/acts_as_list/active_record/acts/scope_method_definer.rb
157
151
  - lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
158
152
  - lib/acts_as_list/active_record/acts/top_of_list_method_definer.rb
153
+ - lib/acts_as_list/active_record/acts/with_connection.rb
159
154
  - lib/acts_as_list/version.rb
160
- - test/helper.rb
161
- - test/shared.rb
162
- - test/shared_array_scope_list.rb
163
- - test/shared_list.rb
164
- - test/shared_list_sub.rb
165
- - test/shared_no_addition.rb
166
- - test/shared_quoting.rb
167
- - test/shared_top_addition.rb
168
- - test/shared_zero_based.rb
169
- - test/support/ci_database.yml
170
- - test/support/database.yml
171
- - test/test_default_scope_with_select.rb
172
- - test/test_joined_list.rb
173
- - test/test_list.rb
174
- - test/test_no_update_for_extra_classes.rb
175
- - test/test_no_update_for_scope_destruction.rb
176
- - test/test_no_update_for_subclasses.rb
177
- - test/test_scope_with_user_defined_foreign_key.rb
178
155
  homepage: https://github.com/brendon/acts_as_list
179
156
  licenses:
180
157
  - MIT
@@ -203,22 +180,4 @@ signing_key:
203
180
  specification_version: 4
204
181
  summary: A gem adding sorting, reordering capabilities to an active_record model,
205
182
  allowing it to act as a list
206
- test_files:
207
- - test/helper.rb
208
- - test/shared.rb
209
- - test/shared_array_scope_list.rb
210
- - test/shared_list.rb
211
- - test/shared_list_sub.rb
212
- - test/shared_no_addition.rb
213
- - test/shared_quoting.rb
214
- - test/shared_top_addition.rb
215
- - test/shared_zero_based.rb
216
- - test/support/ci_database.yml
217
- - test/support/database.yml
218
- - test/test_default_scope_with_select.rb
219
- - test/test_joined_list.rb
220
- - test/test_list.rb
221
- - test/test_no_update_for_extra_classes.rb
222
- - test/test_no_update_for_scope_destruction.rb
223
- - test/test_no_update_for_subclasses.rb
224
- - test/test_scope_with_user_defined_foreign_key.rb
183
+ test_files: []
data/.github/FUNDING.yml DELETED
@@ -1,3 +0,0 @@
1
- # These are supported funding model platforms
2
-
3
- github: [brendon]
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: "github-actions"
4
- directory: "/"
5
- schedule:
6
- interval: "weekly"
@@ -1,62 +0,0 @@
1
- name: Continuous Integration
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
- pull_request:
8
-
9
- jobs:
10
- tests:
11
- runs-on: ubuntu-latest
12
- name: Ruby ${{ matrix.ruby }}, DB ${{ matrix.db }}, Rails ${{ matrix.rails }}
13
- strategy:
14
- fail-fast: false
15
- matrix:
16
- ruby:
17
- - '3.0'
18
- - '3.1'
19
- - '3.2'
20
- - '3.3'
21
- rails:
22
- - '6.1'
23
- - '7.0'
24
- - '7.1'
25
- db:
26
- - mysql
27
- - postgresql
28
- - sqlite
29
- exclude:
30
- - rails: '7.0'
31
- ruby: '3.1'
32
- - rails: '7.0'
33
- ruby: '3.2'
34
- - rails: '7.0'
35
- ruby: '3.3'
36
- env:
37
- DB: ${{ matrix.db }}
38
- RAILS_VERSION: ${{ matrix.rails }}
39
- steps:
40
- - uses: actions/checkout@v4
41
- - name: Set up Ruby
42
- uses: ruby/setup-ruby@v1
43
- with:
44
- ruby-version: ${{ matrix.ruby }}
45
- bundler-cache: true
46
- - name: Enable MySQL
47
- if: ${{ matrix.db == 'mysql' }}
48
- run: sudo systemctl start mysql.service
49
- - name: Create MySQL Database
50
- if: ${{ matrix.db == 'mysql' }}
51
- run: mysql -u root -proot -e 'CREATE DATABASE runner;'
52
- - name: Enable PostgreSQL
53
- if: ${{ matrix.db == 'postgresql' }}
54
- run: sudo systemctl start postgresql.service
55
- - name: Create PostgreSQL User
56
- if: ${{ matrix.db == 'postgresql' }}
57
- run: sudo -u postgres -i createuser runner -s
58
- - name: Create PostgreSQL Database
59
- if: ${{ matrix.db == 'postgresql' }}
60
- run: createdb runner
61
- - name: Run the default task
62
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,13 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .rvmrc
6
- *.tmproj
7
- .rbenv-version
8
- .ruby-gemset
9
- .ruby-version
10
- .DS_Store
11
- /tmp/
12
- /db/
13
- file::memory*
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in positioning.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 13.0"
7
-
8
- gem "minitest", "~> 5.0"
9
-
10
- if ENV["RAILS_VERSION"]
11
- gem "activerecord", ENV["RAILS_VERSION"]
12
- gem "activesupport", ENV["RAILS_VERSION"]
13
- end
data/acts_as_list.gemspec DELETED
@@ -1,40 +0,0 @@
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
- # Description Meta...
7
- s.name = "acts_as_list"
8
- s.version = ActiveRecord::Acts::List::VERSION
9
- s.platform = Gem::Platform::RUBY
10
- s.authors = ["Swanand Pagnis", "Brendon Muir"]
11
- s.email = %w(swanand.pagnis@gmail.com brendon@spikeatschool.co.nz)
12
- s.homepage = "https://github.com/brendon/acts_as_list"
13
- s.summary = "A gem adding sorting, reordering capabilities to an active_record model, allowing it to act as a list"
14
- s.description = '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.'
15
- s.license = "MIT"
16
- s.required_ruby_version = ">= 2.5"
17
-
18
- if s.respond_to?(:metadata)
19
- s.metadata['changelog_uri'] = 'https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md'
20
- s.metadata['source_code_uri'] = 'https://github.com/brendon/acts_as_list'
21
- s.metadata['bug_tracker_uri'] = 'https://github.com/brendon/acts_as_list/issues'
22
- s.metadata['rubygems_mfa_required'] = 'true'
23
- end
24
-
25
- # Load Paths...
26
- s.files = `git ls-files`.split("\n")
27
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
- s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
29
- s.require_paths = ["lib"]
30
-
31
- # Dependencies (installed via "bundle install")
32
- s.add_dependency "activerecord", ">= 6.1"
33
- s.add_dependency "activesupport", ">= 6.1"
34
- s.add_development_dependency "minitest-hooks", "~> 1.5.1"
35
- s.add_development_dependency "mocha", "~> 2.1.0"
36
- s.add_development_dependency "timecop", "~> 0.9.8"
37
- s.add_development_dependency "mysql2", "~> 0.5.6"
38
- s.add_development_dependency "pg", "~> 1.5.5"
39
- s.add_development_dependency "sqlite3", "~> 1.7.2"
40
- end
data/test/helper.rb DELETED
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # $DEBUG = true
4
-
5
- require "rubygems"
6
- require "bundler/setup"
7
- begin
8
- Bundler.setup(:default, :development)
9
- rescue Bundler::BundlerError => e
10
- $stderr.puts e.message
11
- $stderr.puts "Run `bundle install` to install missing gems"
12
- exit e.status_code
13
- end
14
- require "active_record"
15
- require "minitest/autorun"
16
- require "mocha/minitest"
17
- require "#{File.dirname(__FILE__)}/../init"
18
-
19
- ENV["DB"] = "mysql" unless ENV["DB"]
20
-
21
- if defined?(ActiveRecord::VERSION) &&
22
- ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
23
-
24
- # Was removed in Rails 5 and is effectively true.
25
- ActiveRecord::Base.raise_in_transactional_callbacks = true
26
- end
27
-
28
- database_configuration = ENV["CI"] ? "test/support/ci_database.yml" : "test/support/database.yml"
29
-
30
- ActiveRecord::Base.configurations = YAML.safe_load(IO.read(database_configuration))
31
- ActiveRecord::Base.establish_connection(ENV["DB"].to_sym)
32
- ActiveRecord::Schema.verbose = false
33
-
34
- def teardown_db
35
- if ActiveRecord::VERSION::MAJOR >= 5
36
- tables = ActiveRecord::Base.connection.data_sources
37
- else
38
- tables = ActiveRecord::Base.connection.tables
39
- end
40
-
41
- tables.each do |table|
42
- ActiveRecord::Base.connection.drop_table(table)
43
- end
44
- end
45
-
46
- require "shared"
47
-
48
- # require 'logger'
49
- # ActiveRecord::Base.logger = Logger.new(STDOUT)
50
-
51
- def assert_equal_or_nil(a, b)
52
- if a.nil?
53
- assert_nil b
54
- else
55
- assert_equal a, b
56
- end
57
- end
58
-
59
- def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord deprecation warning raised when we didn\'t expect it', pass_message = 'No ActiveRecord deprecation raised')
60
- original_behavior = active_record_deprecator.behavior
61
- active_record_deprecator.behavior = :raise
62
- begin
63
- yield
64
- rescue ActiveSupport::DeprecationException => e
65
- flunk "#{failure_message}: #{e}"
66
- rescue
67
- raise
68
- else
69
- pass pass_message
70
- end
71
- ensure
72
- active_record_deprecator.behavior = original_behavior
73
- end
74
-
75
- def active_record_deprecator
76
- if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR >= 1 || ActiveRecord::VERSION::MAJOR > 7
77
- ActiveRecord.deprecator
78
- else
79
- ActiveSupport::Deprecation
80
- end
81
- end
data/test/shared.rb DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Common shared behaviour.
4
- module Shared
5
- autoload :List, 'shared_list'
6
- autoload :ListSub, 'shared_list_sub'
7
- autoload :ZeroBased, 'shared_zero_based'
8
- autoload :ArrayScopeList, 'shared_array_scope_list'
9
- autoload :TopAddition, 'shared_top_addition'
10
- autoload :NoAddition, 'shared_no_addition'
11
- autoload :Quoting, 'shared_quoting'
12
- end