awesome_nested_set 2.1.1 → 2.1.2

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.
@@ -62,17 +62,24 @@ module CollectiveIdea #:nodoc:
62
62
  extend Columns
63
63
 
64
64
  belongs_to :parent, :class_name => self.base_class.to_s,
65
+ :foreign_key => parent_column_name,
66
+ :counter_cache => options[:counter_cache],
67
+ :inverse_of => (:children unless options[:polymorphic]),
68
+ :polymorphic => options[:polymorphic]
69
+
70
+ has_many_children_options = {
71
+ :class_name => self.base_class.to_s,
65
72
  :foreign_key => parent_column_name,
66
- :counter_cache => options[:counter_cache],
67
- :inverse_of => (:children unless options[:polymorphic]),
68
- :polymorphic => options[:polymorphic]
69
- has_many :children, :class_name => self.base_class.to_s,
70
- :foreign_key => parent_column_name, :order => left_column_name,
73
+ :order => left_column_name,
71
74
  :inverse_of => (:parent unless options[:polymorphic]),
72
- :before_add => options[:before_add],
73
- :after_add => options[:after_add],
74
- :before_remove => options[:before_remove],
75
- :after_remove => options[:after_remove]
75
+ }
76
+
77
+ # Add callbacks, if they were supplied.. otherwise, we don't want them.
78
+ [:before_add, :after_add, :before_remove, :after_remove].each do |ar_callback|
79
+ has_many_children_options.update(ar_callback => options[ar_callback]) if options[ar_callback]
80
+ end
81
+
82
+ has_many :children, has_many_children_options
76
83
 
77
84
  attr_accessor :skip_before_destroy
78
85
 
@@ -114,10 +121,10 @@ module CollectiveIdea #:nodoc:
114
121
  left_and_rights_valid? && no_duplicates_for_columns? && all_roots_valid?
115
122
  end
116
123
 
117
- def left_and_rights_valid?
124
+ def left_and_rights_valid?
118
125
  ## AS clause not supported in Oracle in FROM clause for aliasing table name
119
- joins("LEFT OUTER JOIN #{quoted_table_name}" +
120
- (connection.adapter_name.match(/Oracle/).nil? ? " AS " : " ") +
126
+ joins("LEFT OUTER JOIN #{quoted_table_name}" +
127
+ (connection.adapter_name.match(/Oracle/).nil? ? " AS " : " ") +
121
128
  "parent ON " +
122
129
  "#{quoted_table_name}.#{quoted_parent_column_name} = parent.#{primary_key}").
123
130
  where(
@@ -222,7 +229,7 @@ module CollectiveIdea #:nodoc:
222
229
  yield(o, path.length - 1)
223
230
  end
224
231
  end
225
-
232
+
226
233
  # Same as each_with_level - Accepts a string as a second argument to sort the list
227
234
  # Example:
228
235
  # Category.each_with_level(Category.root.self_and_descendants, :sort_by_this_column) do |o, level|
@@ -250,10 +257,10 @@ module CollectiveIdea #:nodoc:
250
257
  if !children.empty?
251
258
  children.sort_by! &order
252
259
  children.each { |c| yield(c, path.length-1) }
253
- end
260
+ end
254
261
  end
255
262
  end
256
-
263
+
257
264
  # Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
258
265
  #
259
266
  # category.self_and_descendants.count
@@ -454,7 +461,7 @@ module CollectiveIdea #:nodoc:
454
461
 
455
462
  nested_set_scope.where(:id => id).update_all(["#{quoted_depth_column_name} = ?", level])
456
463
  end
457
- self[:depth] = self.level
464
+ self[depth_column_name.to_sym] = self.level
458
465
  end
459
466
  end
460
467
 
@@ -1,3 +1,3 @@
1
1
  module AwesomeNestedSet
2
- VERSION = '2.1.1' unless defined?(::AwesomeNestedSet::VERSION)
2
+ VERSION = '2.1.2' unless defined?(::AwesomeNestedSet::VERSION)
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awesome_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 1
10
- version: 2.1.1
9
+ - 2
10
+ version: 2.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Keepers
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-01-25 00:00:00 Z
20
+ date: 2012-01-26 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: activerecord