Skip to content

Commit

Permalink
Merge pull request #194 from mdsol/fix/remove-will-paginate
Browse files Browse the repository at this point in the history
[MCC-1045698] Replace `will_paginate` with `kaminari`
  • Loading branch information
cmcinnes-mdsol authored Apr 4, 2023
2 parents 34a0e24 + a5e9b31 commit 4744b00
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.6
2.7.7
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.0.4
* Replaced `will_paginate` with `kaminari`.

## 4.0.3
* Updated PostgreSQL `operations_for_operation_sets` CTE to pre-aggregate `accessible_operations` before joining to
`policy_elements` for performance optimizations.
Expand Down
1 change: 0 additions & 1 deletion lib/policy_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require 'securerandom'
require 'active_support/inflector'
require 'set'
require 'will_paginate/array'

# require all adapters
Dir.glob(File.dirname(File.absolute_path(__FILE__)) + '/policy_machine_storage_adapters/*.rb').each{ |f| require f }
Expand Down
2 changes: 1 addition & 1 deletion lib/policy_machine/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class PolicyMachine
VERSION = "4.0.3"
VERSION = "4.0.4"
end
4 changes: 2 additions & 2 deletions lib/policy_machine_storage_adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

begin
require 'active_record'
require 'kaminari'
rescue LoadError
active_record_unavailable = true
end
Expand Down Expand Up @@ -141,7 +142,6 @@ def self.class_for_type(pe_type)
end

class ApplicationRecord < ::ActiveRecord::Base
require 'will_paginate/active_record'
self.abstract_class = true
end

Expand Down Expand Up @@ -1210,7 +1210,7 @@ def filter_by_include_conditions(scope:, include_conditions:, klass:)
def paginate_scope(scope:, options:)
if options[:per_page]
page = options[:page] || 1
scope = scope.order(:id).paginate(page: page, per_page: options[:per_page])
scope = scope.order(:id).page(page).per(options[:per_page])
end
scope
end
Expand Down
5 changes: 3 additions & 2 deletions lib/policy_machine_storage_adapters/in_memory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'policy_machine'
require 'kaminari'

# This class stores policy elements in memory and
# exposes required operations for managing/querying these elements.
Expand Down Expand Up @@ -29,7 +30,7 @@ def buffering?
end

# Find all policy elements of type pe_type
# The results are paginated via will_paginate using the pagination params in the params hash
# The results are paginated via kaminari using the pagination params in the params hash
# The find is case insensitive to the conditions
define_method("find_all_of_type_#{pe_type}") do |options = {}|
conditions = options.slice!(:per_page, :page, :ignore_case).merge(pe_type: pe_type)
Expand All @@ -49,7 +50,7 @@ def buffering?
# TODO: Refactor pagination block into another method and make find_all method smaller
if options[:per_page]
page = options[:page] ? options[:page] : 1
paginated_elements = elements.paginate(options.slice(:per_page, :page))
paginated_elements = Kaminari.paginate_array(elements).page(page).per(options[:per_page])
else
paginated_elements = elements
end
Expand Down
2 changes: 1 addition & 1 deletion policy_machine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Gem::Specification.new do |s|

s.add_dependency('activesupport')
s.add_dependency('activerecord') #TODO optional dependency when not using active record adapter
s.add_dependency('will_paginate')
s.add_dependency('bootsnap')
s.add_dependency('kaminari')
s.add_dependency('listen')

# Only required in ActiveRecord mode
Expand Down

0 comments on commit 4744b00

Please sign in to comment.