acts_as_sane_tree 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ === v2.0.5
2
+ * Force integer type on depth result or nil if undetermined
3
+ * Fixed query building bug in #nodes_within
4
+
1
5
  === v2.0.4
2
6
  * Clean up default scope methodology within nodes_and_descendants (fixes scope smashing issues in rails 3)
3
7
  * Clean up #depth implementation to be direct instead of incurring AR overhead
@@ -1,7 +1,7 @@
1
1
  require 'acts_as_sane_tree/acts_as_sane_tree'
2
2
  require 'acts_as_sane_tree/version'
3
3
 
4
- if(defined?(Rails))
4
+ if(defined?(ActiveRecord))
5
5
  ActiveRecord::Base.send :include, ActsAsSaneTree
6
6
  if(defined?(ActiveRecord::Relation))
7
7
  ActiveRecord::Relation.send :include, ActsAsSaneTree
@@ -92,7 +92,7 @@ module ActsAsSaneTree
92
92
  FROM crumbs
93
93
  JOIN #{self.class.configuration[:class].table_name} alias1 ON alias1.id = crumbs.parent_id
94
94
  ) SELECT level FROM crumbs ORDER BY level DESC LIMIT 1"
95
- ActiveRecord::Base.connection.select_all(query).first.try(:[], 'level')
95
+ ActiveRecord::Base.connection.select_all(query).first.try(:[], 'level').try(:to_i)
96
96
  end
97
97
  end
98
98
  end
@@ -3,7 +3,7 @@ module ActsAsSaneTree
3
3
 
4
4
  # Check if we are in rails 3
5
5
  def rails_3?
6
- @is_3 ||= Rails.version.split('.').first == '3'
6
+ @is_3 ||= !defined?(Arel).nil?
7
7
  end
8
8
 
9
9
  # Return all root nodes
@@ -64,7 +64,7 @@ module ActsAsSaneTree
64
64
  else
65
65
  query =
66
66
  "(WITH RECURSIVE crumbs AS (
67
- SELECT #{configuration[:class].table_name}.*, 0 AS depth FROM #{configuration[:class].table_name} WHERE id in (\#{s.join(', ')})
67
+ SELECT #{configuration[:class].table_name}.*, 0 AS depth FROM #{configuration[:class].table_name} WHERE id in (#{s.join(', ')})
68
68
  UNION ALL
69
69
  SELECT alias1.*, crumbs.depth + 1 FROM crumbs JOIN #{configuration[:class].table_name} alias1 on alias1.parent_id = crumbs.id
70
70
  #{configuration[:max_depth] ? "WHERE crumbs.depth + 1 < #{configuration[:max_depth].to_i}" : ''}
@@ -99,9 +99,9 @@ module ActsAsSaneTree
99
99
  depth_restriction = "WHERE crumbs.depth + 1 < #{depth}" if depth
100
100
  depth_clause = nil
101
101
  if(at_depth)
102
- depth_clause = "#{configuration[:class].table_name}.depth + 1 = #{at_depth.to_i}"
102
+ depth_clause = "#{configuration[:class].table_name}.depth + 1 = #{at_depth.to_i + 1}"
103
103
  elsif(depth)
104
- depth_clause = "#{configuration[:class].table_name}.depth + 1 < #{depth.to_i}"
104
+ depth_clause = "#{configuration[:class].table_name}.depth + 1 < #{depth.to_i + 2}"
105
105
  end
106
106
  base_ids = args.map{|x| x.is_a?(ActiveRecord::Base) ? x.id : x.to_i}
107
107
  query =
@@ -13,6 +13,6 @@ module ActsAsSaneTree
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('2.0.4')
16
+ VERSION = Version.new('2.0.5')
17
17
  end
18
18
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_sane_tree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 4
10
- version: 2.0.4
9
+ - 5
10
+ version: 2.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-16 00:00:00 -07:00
18
+ date: 2012-01-25 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  requirements: []
82
82
 
83
83
  rubyforge_project:
84
- rubygems_version: 1.6.2
84
+ rubygems_version: 1.4.2
85
85
  signing_key:
86
86
  specification_version: 3
87
87
  summary: Sane tree builder for ActiveRecord and Postgresql