has_hierarchy 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/has_hierarchy.gemspec +2 -2
- data/lib/has_hierarchy/counter_cache.rb +4 -0
- data/lib/has_hierarchy/path.rb +7 -7
- data/lib/has_hierarchy/version.rb +1 -1
- data/lib/has_hierarchy.rb +1 -5
- data/spec/tree.rb +4 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d673f21a344bfee6de33caa82e9d3828766b4c
|
4
|
+
data.tar.gz: bfd3039a2107c54291497898345bad43024413aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 324bc0f6c38e8f8ca92c1f350ec204a8925c4820b8b6dbe402f65b28e5d36176e9c9b45f9663a424c51d46be9c2755f80a54d5c8fab6e01d0e494f9a0711beae
|
7
|
+
data.tar.gz: 7e1fc5c1b53e078bec6e1bc752775fd0cfd0aa6f1a0dc118f2cc9f25540c28402b9c942939f972806b465d8ad9d4d8e9ec282ecf36972d6ba3441e8b03881b1b
|
data/README.md
CHANGED
@@ -90,8 +90,10 @@ Item.ordered.tree
|
|
90
90
|
# }
|
91
91
|
# }
|
92
92
|
|
93
|
-
Item.find_by_path('bar/qux/quux')
|
93
|
+
quux = Item.find_by_path('bar/qux/quux')
|
94
94
|
# => quux
|
95
|
+
quux.full_path
|
96
|
+
# => 'bar/qux/quux'
|
95
97
|
```
|
96
98
|
|
97
99
|
Operations on nodes:
|
@@ -118,8 +120,8 @@ bar.descendants # => [ qux, quux, baz ]
|
|
118
120
|
|
119
121
|
Ordering (see [has_order](https://github.com/kolesnikovde/has_order)):
|
120
122
|
```ruby
|
121
|
-
bar.previous_siblings # => [ foo
|
122
|
-
foo.next_siblings # => [
|
123
|
+
bar.previous_siblings # => [ foo ]
|
124
|
+
foo.next_siblings # => [ bar ]
|
123
125
|
|
124
126
|
foo.move_after(quux)
|
125
127
|
Item.ordered.tree
|
data/has_hierarchy.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
|
10
10
|
spec.authors = ['Kolesnikov Danil']
|
11
11
|
spec.email = ['kolesnikovde@gmail.com']
|
12
|
-
spec.description = '
|
13
|
-
spec.summary = '
|
12
|
+
spec.description = 'Tree behavior for ActiveRecord models and Mongoid documents.'
|
13
|
+
spec.summary = 'Tree behavior for ActiveRecord models and Mongoid documents.'
|
14
14
|
spec.homepage = 'https://github.com/kolesnikovde/has_hierarchy'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
data/lib/has_hierarchy/path.rb
CHANGED
@@ -3,8 +3,7 @@ module HasHierarchy
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
before_update :rebuild_subtree, if: :need_to_rebuild_subtree?
|
6
|
+
before_save :rebuild_subtree, if: :need_to_rebuild_subtree?
|
8
7
|
end
|
9
8
|
|
10
9
|
module ClassMethods
|
@@ -71,15 +70,16 @@ module HasHierarchy
|
|
71
70
|
end
|
72
71
|
|
73
72
|
def populate_path(path = nil)
|
74
|
-
self.path = root? ? '' : (path || parent.path_for_children)
|
75
73
|
end
|
76
74
|
|
77
75
|
def rebuild_subtree(path = nil)
|
78
|
-
|
76
|
+
self.path = root? ? '' : (path || parent.path_for_children)
|
79
77
|
|
80
|
-
|
81
|
-
child
|
82
|
-
|
78
|
+
unless new_record?
|
79
|
+
children.each do |child|
|
80
|
+
child.rebuild_subtree(path_for_children)
|
81
|
+
child.save!
|
82
|
+
end
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
data/lib/has_hierarchy.rb
CHANGED
data/spec/tree.rb
CHANGED
@@ -225,8 +225,8 @@ shared_examples 'materialized path' do
|
|
225
225
|
let(:new_ancestors) { [ foo ] }
|
226
226
|
|
227
227
|
before do
|
228
|
-
|
229
|
-
|
228
|
+
qux.parent = new_parent
|
229
|
+
qux.save!
|
230
230
|
reload_items
|
231
231
|
end
|
232
232
|
|
@@ -241,16 +241,12 @@ shared_examples 'materialized path' do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'changes ancestors' do
|
244
|
-
expect(
|
244
|
+
expect(qux.ancestors).to match_array(new_ancestors)
|
245
245
|
end
|
246
246
|
|
247
247
|
it 'applies to all descendants' do
|
248
|
-
|
248
|
+
qux.children.each do |child|
|
249
249
|
expect(child).to be_descendant_of(new_parent)
|
250
|
-
|
251
|
-
child.children.each do |subchild|
|
252
|
-
expect(subchild).to be_descendant_of(new_parent)
|
253
|
-
end
|
254
250
|
end
|
255
251
|
end
|
256
252
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_hierarchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kolesnikov Danil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.2'
|
139
|
-
description:
|
139
|
+
description: Tree behavior for ActiveRecord models and Mongoid documents.
|
140
140
|
email:
|
141
141
|
- kolesnikovde@gmail.com
|
142
142
|
executables: []
|
@@ -192,7 +192,7 @@ rubyforge_project:
|
|
192
192
|
rubygems_version: 2.2.2
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
|
-
summary:
|
195
|
+
summary: Tree behavior for ActiveRecord models and Mongoid documents.
|
196
196
|
test_files:
|
197
197
|
- spec/has_hierarchy_spec.rb
|
198
198
|
- spec/spec_helper.rb
|