Skip to content

Commit 6bbb492

Browse files
committedMay 14, 2014
Syntax deprecation fix
1 parent 4761d53 commit 6bbb492

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed
 

‎lib/closure_tree/digraphs.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def to_digraph_label
1414
module ClassMethods
1515
# Renders the given scope as a DOT digraph, suitable for rendering by Graphviz
1616
def to_dot_digraph(tree_scope)
17-
id_to_instance = tree_scope.inject({}) { |h, ea| h[ea.id] = ea; h }
17+
id_to_instance = tree_scope.reduce({}) { |h, ea| h[ea.id] = ea; h }
1818
output = StringIO.new
1919
output << "digraph G {\n"
2020
tree_scope.each do |ea|
21-
if id_to_instance.has_key? ea._ct_parent_id
21+
if id_to_instance.key? ea._ct_parent_id
2222
output << " #{ea._ct_parent_id} -> #{ea._ct_id}\n"
2323
end
2424
output << " #{ea._ct_id} [label=\"#{ea.to_digraph_label}\"]\n"

‎lib/closure_tree/model.rb

+23-24
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,44 @@ module Model
66

77
included do
88
belongs_to :parent,
9-
:class_name => _ct.model_class.to_s,
10-
:foreign_key => _ct.parent_column_name,
11-
:inverse_of => :children
9+
class_name: _ct.model_class.to_s,
10+
foreign_key: _ct.parent_column_name,
11+
inverse_of: :children
1212

13+
# TODO, remove when activerecord 3.2 support is dropped
1314
attr_accessible :parent if _ct.use_attr_accessible?
1415

1516
order_by_generations = "#{_ct.quoted_hierarchy_table_name}.generations asc"
1617

1718
has_many :children, *_ct.has_many_with_order_option(
18-
:class_name => _ct.model_class.to_s,
19-
:foreign_key => _ct.parent_column_name,
20-
:dependent => _ct.options[:dependent],
21-
:inverse_of => :parent)
19+
class_name: _ct.model_class.to_s,
20+
foreign_key: _ct.parent_column_name,
21+
dependent: _ct.options[:dependent],
22+
inverse_of: :parent)
2223

2324
has_many :ancestor_hierarchies, *_ct.has_many_without_order_option(
24-
:class_name => _ct.hierarchy_class_name,
25-
:foreign_key => "descendant_id",
26-
:order => order_by_generations)
25+
class_name: _ct.hierarchy_class_name,
26+
foreign_key: 'descendant_id',
27+
order: order_by_generations)
2728

2829
has_many :self_and_ancestors, *_ct.has_many_without_order_option(
29-
:through => :ancestor_hierarchies,
30-
:source => :ancestor,
31-
:order => order_by_generations)
30+
through: :ancestor_hierarchies,
31+
source: :ancestor,
32+
order: order_by_generations)
3233

3334
has_many :descendant_hierarchies, *_ct.has_many_without_order_option(
34-
:class_name => _ct.hierarchy_class_name,
35-
:foreign_key => "ancestor_id",
36-
:order => order_by_generations)
35+
class_name: _ct.hierarchy_class_name,
36+
foreign_key: 'ancestor_id',
37+
order: order_by_generations)
3738

3839
has_many :self_and_descendants, *_ct.has_many_with_order_option(
39-
:through => :descendant_hierarchies,
40-
:source => :descendant,
41-
:order => order_by_generations)
40+
through: :descendant_hierarchies,
41+
source: :descendant,
42+
order: order_by_generations)
4243
end
4344

4445
# Delegate to the Support instance on the class:
45-
def _ct
46-
self.class._ct
47-
end
46+
delegate :_ct, to: :class
4847

4948
# Returns true if this node has no parents.
5049
def root?
@@ -76,7 +75,7 @@ def depth
7675
ancestors.size
7776
end
7877

79-
alias :level :depth
78+
alias_method :level, :depth
8079

8180
def ancestors
8281
without_self(self_and_ancestors)
@@ -94,7 +93,7 @@ def self_and_ancestors_ids
9493
# to the +name_column+.
9594
# (so child.ancestry_path == +%w{grandparent parent child}+
9695
def ancestry_path(to_s_column = _ct.name_column)
97-
self_and_ancestors.reverse.collect { |n| n.send to_s_column.to_sym }
96+
self_and_ancestors.reverse.map { |n| n.send to_s_column.to_sym }
9897
end
9998

10099
def child_ids

‎spec/model_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'spec_helper'
2+
3+
describe ClosureTree::Model do
4+
describe '#_ct' do
5+
it 'should delegate to the Support instance on the class' do
6+
expect(Tag.new._ct).to eq(Tag._ct)
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)