Skip to content

Commit 27095b1

Browse files
authored
Merge pull request #360 from aubinlrx/tweak/deprecation_warning_ruby_27
Fix kwargs usage for Ruby 2.7
2 parents 9b5245e + cfff7b1 commit 27095b1

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

lib/closure_tree/model.rb

+11-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Model
66

77
included do
88

9-
belongs_to :parent, nil, *_ct.belongs_to_with_optional_option(
9+
belongs_to :parent, nil, **_ct.belongs_to_with_optional_option(
1010
class_name: _ct.model_class.to_s,
1111
foreign_key: _ct.parent_column_name,
1212
inverse_of: :children,
@@ -15,11 +15,11 @@ module Model
1515

1616
order_by_generations = -> { Arel.sql("#{_ct.quoted_hierarchy_table_name}.generations ASC") }
1717

18-
has_many :children, *_ct.has_many_with_order_option(
18+
has_many :children, *_ct.has_many_order_with_option, **{
1919
class_name: _ct.model_class.to_s,
2020
foreign_key: _ct.parent_column_name,
2121
dependent: _ct.options[:dependent],
22-
inverse_of: :parent) do
22+
inverse_of: :parent } do
2323
# We have to redefine hash_tree because the activerecord relation is already scoped to parent_id.
2424
def hash_tree(options = {})
2525
# we want limit_depth + 1 because we don't do self_and_descendants.
@@ -28,25 +28,21 @@ def hash_tree(options = {})
2828
end
2929
end
3030

31-
has_many :ancestor_hierarchies, *_ct.has_many_without_order_option(
31+
has_many :ancestor_hierarchies, *_ct.has_many_order_without_option(order_by_generations),
3232
class_name: _ct.hierarchy_class_name,
33-
foreign_key: 'descendant_id',
34-
order: order_by_generations)
33+
foreign_key: 'descendant_id'
3534

36-
has_many :self_and_ancestors, *_ct.has_many_without_order_option(
35+
has_many :self_and_ancestors, *_ct.has_many_order_without_option(order_by_generations),
3736
through: :ancestor_hierarchies,
38-
source: :ancestor,
39-
order: order_by_generations)
37+
source: :ancestor
4038

41-
has_many :descendant_hierarchies, *_ct.has_many_without_order_option(
39+
has_many :descendant_hierarchies, *_ct.has_many_order_without_option(order_by_generations),
4240
class_name: _ct.hierarchy_class_name,
43-
foreign_key: 'ancestor_id',
44-
order: order_by_generations)
41+
foreign_key: 'ancestor_id'
4542

46-
has_many :self_and_descendants, *_ct.has_many_with_order_option(
43+
has_many :self_and_descendants, *_ct.has_many_order_with_option(order_by_generations),
4744
through: :descendant_hierarchies,
48-
source: :descendant,
49-
order: order_by_generations)
45+
source: :descendant
5046
end
5147

5248
# Delegate to the Support instance on the class:

lib/closure_tree/support.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ def scope_with_order(scope, additional_order_by = nil)
8080
end
8181

8282
def belongs_to_with_optional_option(opts)
83-
[ActiveRecord::VERSION::MAJOR < 5 ? opts.except(:optional) : opts]
83+
ActiveRecord::VERSION::MAJOR < 5 ? opts.except(:optional) : opts
8484
end
8585

8686
# lambda-ize the order, but don't apply the default order_option
87-
def has_many_without_order_option(opts)
88-
[lambda { order(opts[:order].call) }, opts.except(:order)]
87+
def has_many_order_without_option(order_by_opt)
88+
[lambda { order(order_by_opt.call) }]
8989
end
9090

91-
def has_many_with_order_option(opts)
92-
order_options = [opts[:order], order_by].compact
91+
def has_many_order_with_option(order_by_opt=nil)
92+
order_options = [order_by_opt, order_by].compact
9393
[lambda {
9494
order_options = order_options.map { |o| o.is_a?(Proc) ? o.call : o }
9595
order(order_options)
96-
}, opts.except(:order)]
96+
}]
9797
end
9898

9999
def ids_from(scope)

0 commit comments

Comments
 (0)