Skip to content

Commit 9b5245e

Browse files
authored
Merge pull request #356 from jmschneider/master
Replace strip_heredoc with squish
2 parents 0686795 + 7a8ac2c commit 9b5245e

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

lib/closure_tree.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'active_record'
2-
require 'active_support/core_ext/string/strip'
32

43
module ClosureTree
54
extend ActiveSupport::Autoload

lib/closure_tree/finders.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def find_or_create_by_path(path, attributes = {})
3434
end
3535

3636
def find_all_by_generation(generation_level)
37-
s = _ct.base_class.joins(<<-SQL.strip_heredoc)
37+
s = _ct.base_class.joins(<<-SQL.squish)
3838
INNER JOIN (
3939
SELECT descendant_id
4040
FROM #{_ct.quoted_hierarchy_table_name}
@@ -70,7 +70,7 @@ def root
7070
end
7171

7272
def leaves
73-
s = joins(<<-SQL.strip_heredoc)
73+
s = joins(<<-SQL.squish)
7474
INNER JOIN (
7575
SELECT ancestor_id
7676
FROM #{_ct.quoted_hierarchy_table_name}
@@ -113,7 +113,7 @@ def lowest_common_ancestor(*descendants)
113113
end
114114

115115
def find_all_by_generation(generation_level)
116-
s = joins(<<-SQL.strip_heredoc)
116+
s = joins(<<-SQL.squish)
117117
INNER JOIN (
118118
SELECT #{primary_key} as root_id
119119
FROM #{_ct.quoted_table_name}
@@ -143,7 +143,7 @@ def find_by_path(path, attributes = {}, parent_id = nil)
143143
last_joined_table = _ct.table_name
144144
path.reverse.each_with_index do |ea, idx|
145145
next_joined_table = "p#{idx}"
146-
scope = scope.joins(<<-SQL.strip_heredoc)
146+
scope = scope.joins(<<-SQL.squish)
147147
INNER JOIN #{_ct.quoted_table_name} #{ _ct.t_alias_keyword } #{next_joined_table}
148148
ON #{next_joined_table}.#{_ct.quoted_id_column_name} =
149149
#{connection.quote_table_name(last_joined_table)}.#{_ct.quoted_parent_column_name}

lib/closure_tree/hash_tree_support.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def default_tree_scope(scope, limit_depth = nil)
44
# Deepest generation, within limit, for each descendant
55
# NOTE: Postgres requires HAVING clauses to always contains aggregate functions (!!)
66
having_clause = limit_depth ? "HAVING MAX(generations) <= #{limit_depth - 1}" : ''
7-
generation_depth = <<-SQL.strip_heredoc
7+
generation_depth = <<-SQL.squish
88
INNER JOIN (
99
SELECT descendant_id, MAX(generations) as depth
1010
FROM #{quoted_hierarchy_table_name}

lib/closure_tree/hierarchy_maintenance.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def rebuild!(called_by_rebuild = false)
6767
delete_hierarchy_references unless (defined? @was_new_record) && @was_new_record
6868
hierarchy_class.create!(:ancestor => self, :descendant => self, :generations => 0)
6969
unless root?
70-
_ct.connection.execute <<-SQL.strip_heredoc
70+
_ct.connection.execute <<-SQL.squish
7171
INSERT INTO #{_ct.quoted_hierarchy_table_name}
7272
(ancestor_id, descendant_id, generations)
7373
SELECT x.ancestor_id, #{_ct.quote(_ct_id)}, x.generations + 1
@@ -94,7 +94,7 @@ def delete_hierarchy_references
9494
# It shouldn't affect performance of postgresql.
9595
# See http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html
9696
# Also: PostgreSQL doesn't support INNER JOIN on DELETE, so we can't use that.
97-
_ct.connection.execute <<-SQL.strip_heredoc
97+
_ct.connection.execute <<-SQL.squish
9898
DELETE FROM #{_ct.quoted_hierarchy_table_name}
9999
WHERE descendant_id IN (
100100
SELECT DISTINCT descendant_id

lib/closure_tree/numeric_deterministic_ordering.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module ClassMethods
5151

5252
# If node is nil, order the whole tree.
5353
def _ct_sum_order_by(node = nil)
54-
stats_sql = <<-SQL.strip_heredoc
54+
stats_sql = <<-SQL.squish
5555
SELECT
5656
count(*) as total_descendants,
5757
max(generations) as max_depth
@@ -74,7 +74,7 @@ def roots_and_descendants_preordered
7474
raise ClosureTree::RootOrderingDisabledError.new("Root ordering is disabled on this model")
7575
end
7676

77-
join_sql = <<-SQL.strip_heredoc
77+
join_sql = <<-SQL.squish
7878
JOIN #{_ct.quoted_hierarchy_table_name} anc_hier
7979
ON anc_hier.descendant_id = #{_ct.quoted_table_name}.#{_ct.quoted_id_column_name}
8080
JOIN #{_ct.quoted_table_name} anc

lib/closure_tree/numeric_order_support.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def reorder_with_parent_id(parent_id, minimum_sort_order_value = nil)
2121
""
2222
end
2323
connection.execute 'SET @i = 0'
24-
connection.execute <<-SQL.strip_heredoc
24+
connection.execute <<-SQL.squish
2525
UPDATE #{quoted_table_name}
2626
SET #{quoted_order_column} = (@i := @i + 1) + #{minimum_sort_order_value.to_i - 1}
2727
WHERE #{where_eq(parent_column_name, parent_id)} #{min_where}
@@ -38,7 +38,7 @@ def reorder_with_parent_id(parent_id, minimum_sort_order_value = nil)
3838
else
3939
""
4040
end
41-
connection.execute <<-SQL.strip_heredoc
41+
connection.execute <<-SQL.squish
4242
UPDATE #{quoted_table_name}
4343
SET #{quoted_order_column(false)} = t.seq + #{minimum_sort_order_value.to_i - 1}
4444
FROM (

0 commit comments

Comments
 (0)