acts_as_sane_tree 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === v2.0.4
2
+ * Clean up default scope methodology within nodes_and_descendants (fixes scope smashing issues in rails 3)
3
+ * Clean up #depth implementation to be direct instead of incurring AR overhead
4
+
1
5
  === v2.0.3
2
6
  * Use ordered hashes when building nested descendants (.nodes_and_descendants method)
3
7
  * Only apply dynamic depth ordering to descendant scoping
@@ -83,33 +83,16 @@ module ActsAsSaneTree
83
83
  # Returns the depth of the current node. 0 depth represents the root of the tree
84
84
  def depth
85
85
  query =
86
- "(WITH RECURSIVE crumbs AS (
87
- SELECT parent_id, 0 AS depth
86
+ "WITH RECURSIVE crumbs AS (
87
+ SELECT parent_id, 0 AS level
88
88
  FROM #{self.class.configuration[:class].table_name}
89
- WHERE id = #{id}
89
+ WHERE id = #{self.id}
90
90
  UNION ALL
91
91
  SELECT alias1.parent_id, level + 1
92
92
  FROM crumbs
93
93
  JOIN #{self.class.configuration[:class].table_name} alias1 ON alias1.id = crumbs.parent_id
94
- ) SELECT depth FROM crumbs) as #{self.class.configuration[:class].table_name}"
95
- if(self.class.rails_3?)
96
- self.class.configuration[:class].send(:with_exclusive_scope) do
97
- self.class.configuration[:class].from(
98
- query
99
- ).order(
100
- "#{self.class.configuration[:class].table_name}.depth DESC"
101
- ).limit(1).try(:first).try(:depth)
102
- end
103
- else
104
- self.class.configuration[:class].send(:with_exclusive_scope) do
105
- self.class.configuration[:class].find(
106
- :first,
107
- :from => query,
108
- :order => "#{self.class.configuration[:class].table_name}.depth DESC",
109
- :limit => 1
110
- ).try(:depth)
111
- end
112
- end
94
+ ) SELECT level FROM crumbs ORDER BY level DESC LIMIT 1"
95
+ ActiveRecord::Base.connection.select_all(query).first.try(:[], 'level')
113
96
  end
114
97
  end
115
98
  end
@@ -121,21 +121,23 @@ module ActsAsSaneTree
121
121
  if(depth_clause)
122
122
  q = q.where(depth_clause)
123
123
  end
124
- q = q.order(Array(configuration[:order]).join(', '))
124
+ if(configuration[:order].present?)
125
+ q = q.order(configuration[:order])
126
+ end
125
127
  else
126
128
  q = configuration[:class].scoped(
127
129
  :from => query,
128
- :conditions => "#{configuration[:class].table_name}.depth >= 0",
129
- :order => Array(configuration[:order]).join(', ')
130
+ :conditions => "#{configuration[:class].table_name}.depth >= 0"
130
131
  )
132
+ if(configuration[:order].present?)
133
+ q = q.scoped(:order => configuration[:order])
134
+ end
131
135
  if(depth_clause)
132
136
  q = q.scoped(:conditions => depth_clause)
133
137
  end
134
138
  end
135
- if(defined?(ActiveRecord::Relation) && (dfs = retrieve_default_find_scope).is_a?(ActiveRecord::Relation))
136
- q = q.scoped(:conditions => dfs.where_values_hash)
137
- else
138
- q = q.scoped(retrieve_default_find_scope)
139
+ unless(rails_3?)
140
+ q = q.scoped(scope(:find))
139
141
  end
140
142
  unless(raw)
141
143
  res = ActiveSupport::OrderedHash.new
@@ -157,11 +159,5 @@ module ActsAsSaneTree
157
159
  end
158
160
  alias_method :nodes_and_descendents, :nodes_and_descendants
159
161
 
160
- private
161
-
162
- def retrieve_default_find_scope
163
- scope(:find).respond_to?(:call) ? scope(:find).call : scope(:find)
164
- end
165
-
166
162
  end
167
163
  end
@@ -1,3 +1,18 @@
1
1
  module ActsAsSaneTree
2
- VERSION = '2.0.3'
2
+ class Version
3
+
4
+ attr_reader :major, :minor, :tiny
5
+
6
+ def initialize(version)
7
+ version = version.split('.')
8
+ @major, @minor, @tiny = [version[0].to_i, version[1].to_i, version[2].to_i]
9
+ end
10
+
11
+ def to_s
12
+ "#{@major}.#{@minor}.#{@tiny}"
13
+ end
14
+ end
15
+
16
+ VERSION = Version.new('2.0.4')
3
17
  end
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: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 3
10
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
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-12 00:00:00 -07:00
18
+ date: 2011-09-16 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency