simple_nested_set 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module SimpleNestedSet
14
14
  before_destroy lambda { |r| r.nested_set.prune_branch }
15
15
 
16
16
  belongs_to :parent, :class_name => self.name
17
- has_many :children, :foreign_key => :parent_id, :class_name => self.base_class.name
17
+ has_many :children, :foreign_key => :parent_id, :class_name => class_of_active_record_descendant(self).name
18
18
 
19
19
  default_scope :order => :lft
20
20
 
@@ -19,7 +19,7 @@ module SimpleNestedSet
19
19
  def initialize(node, attributes)
20
20
  @node, @attributes = node, attributes
21
21
  normalize_attributes!
22
- protect_inconsistent_move!(parent_id, left_id, right_id)
22
+ protect_inconsistent_move!
23
23
  end
24
24
 
25
25
  def perform
@@ -39,14 +39,14 @@ module SimpleNestedSet
39
39
  attributes.each { |key, value| attributes[key] = nil if value == 'null' }
40
40
 
41
41
  # if left_id is given but blank, set right_id to leftmost sibling
42
- if attributes.has_key?(:left_id) && attributes[:left_id].blank? && siblings.any?
43
- attributes[:right_id] = siblings.first.id
44
- end
42
+ attributes[:right_id] = siblings.first.id if blank_given?(:left_id) && siblings.any?
45
43
 
46
44
  # if right_id is given but blank, set left_id to rightmost sibling
47
- if attributes.has_key?(:right_id) && attributes[:right_id].blank? && siblings.any?
48
- attributes[:left_id] = siblings.last.id
49
- end
45
+ attributes[:left_id] = siblings.last.id if blank_given?(:right_id) && siblings.any?
46
+ end
47
+
48
+ def blank_given?(key)
49
+ attributes.has_key?(key) && attributes[key].blank? && siblings.any?
50
50
  end
51
51
 
52
52
  def siblings
@@ -14,8 +14,8 @@ module SimpleNestedSet
14
14
  impossible_move!("A node can't be moved to a different scope") if target && !nested_set.same_scope?(target)
15
15
  end
16
16
 
17
- def protect_inconsistent_move!(parent_id, left_id, right_id)
18
- left = nested_set.find(left_id) if left_id
17
+ def protect_inconsistent_move!
18
+ left = nested_set.find(left_id) if left_id
19
19
  right = nested_set.find(right_id) if right_id
20
20
 
21
21
  if left && right && (!left.right_sibling || left.right_sibling.id != right_id)
@@ -10,7 +10,6 @@ module SimpleNestedSet
10
10
  def initialize(node, target, position)
11
11
  @node, @target, @position = node, target, position
12
12
  @target = nested_set.find(target) if target && !target.is_a?(ActiveRecord::Base)
13
-
14
13
  protect_impossible_move!
15
14
  end
16
15
 
@@ -1,3 +1,3 @@
1
1
  module SimpleNestedSet
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-04 00:00:00 +02:00
18
+ date: 2010-08-12 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency