xylem 0.0.1 → 0.1.0
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 +8 -5
- data/Rakefile +6 -0
- data/bench/acts_as_tree.json +11 -11
- data/bench/ancestry.json +12 -12
- data/bench/awesome_nested_set.json +12 -12
- data/bench/benchmark.rb +3 -4
- data/bench/xylem.json +12 -12
- data/bootstrap.sh +6 -3
- data/gemfiles/ar_5beta.gemfile +1 -1
- data/lib/xylem/version.rb +1 -1
- data/lib/xylem.rb +4 -0
- data/test/xylem_tests.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a66a285e5aacfa913b065f184b825218e6cfa07d
|
4
|
+
data.tar.gz: 7edc791c60d6c1638c460c2975a125ac746af45a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cddec6fbfc58582508343ba1b1fd5b32ff22ca67468df10a4491e9a1eb78b9f527b80429777f0144a452305b43e86bb417b4a381cb80f17c50c3ef98fd487d77
|
7
|
+
data.tar.gz: dd325095109b73ec7e9ae6a0db5abd5ecf6d5344483a6703c363bc1286ce350ea62de865e94d6040020eaab6e424ba444c5946ff0db4f53b0ba7c6faac4ef4b5
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ Also queries that traverse the tree (such as get ancestors or descendants of a n
|
|
19
19
|
Add this line to your application's Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
gem 'xylem',
|
22
|
+
gem 'xylem', '~> 0.0.1'
|
23
23
|
```
|
24
24
|
|
25
25
|
And then execute:
|
@@ -48,8 +48,8 @@ Some notes regarding migration:
|
|
48
48
|
* Add a foreign key is optional, but it's recommended to guarantee data consistency
|
49
49
|
* The `foreign_key: true` option is available in [rails 4.2.1](https://github.com/rails/rails/blob/v4.2.1/activerecord/CHANGELOG.md) or newer
|
50
50
|
|
51
|
-
Now you need to enable the tree behavior in
|
52
|
-
Let's
|
51
|
+
Now you need to enable the tree behavior in our model by adding the `acts_as_tree` directive in it.
|
52
|
+
Let's continue supposing that you're dealing with a model called `Menu`, you should add the following:
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
class Menu < ActiveRecord::Base
|
@@ -88,14 +88,15 @@ Xylem adds the following class methods to a class with the `acts_as_tree` direct
|
|
88
88
|
* `self_and_ancestors` returns the ancestors from the root to the node itself. Ordered from the root to the node.
|
89
89
|
* `descendants` returns all the descendants of the given node. Ordered by depth from the closer to the node to the more distant ones.
|
90
90
|
* `self_and_descendants` returns the node and all it's descendants. Ordered by depth with the node first and the descendants later.
|
91
|
-
* `root` returns the current node root.
|
92
|
-
* `siblings` returns the siblings
|
91
|
+
* `root` returns the current node's root.
|
92
|
+
* `siblings` returns the node's siblings, excluding itself.
|
93
93
|
* `self_and_siblings` returns the node and it's siblings.
|
94
94
|
* `children` returns the direct children of the node.
|
95
95
|
* `self_and_children` returns the node and it's direct children.
|
96
96
|
* `parent` returns the node parent.
|
97
97
|
* `root?` returns true if the current node is a root, false otherwise.
|
98
98
|
* `leaf?` returns true if the current node is a leaf, false otherwise.
|
99
|
+
* `leaves`: returns the leaves from the current node
|
99
100
|
|
100
101
|
### Examples
|
101
102
|
|
@@ -121,6 +122,8 @@ child1.root # => root
|
|
121
122
|
child1.self_and_ancestors # => [ root, child1 ]
|
122
123
|
|
123
124
|
child1.self_and_siblings # => [ child1, child2 ]
|
125
|
+
|
126
|
+
child2.leaves # => [ subchild ]
|
124
127
|
```
|
125
128
|
|
126
129
|
## Dependencies
|
data/Rakefile
CHANGED
data/bench/acts_as_tree.json
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"name": "insertion",
|
4
|
-
"ips":
|
5
|
-
"stddev":
|
4
|
+
"ips": 1036.8914832940068,
|
5
|
+
"stddev": 195
|
6
6
|
},
|
7
7
|
{
|
8
8
|
"name": "parent",
|
9
|
-
"ips":
|
10
|
-
"stddev":
|
9
|
+
"ips": 1215.4998688546427,
|
10
|
+
"stddev": 252
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"name": "children",
|
14
|
-
"ips":
|
15
|
-
"stddev":
|
14
|
+
"ips": 5.281724863837879,
|
15
|
+
"stddev": 1
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"name": "roots",
|
19
|
-
"ips":
|
20
|
-
"stddev":
|
19
|
+
"ips": 2607.3692118170793,
|
20
|
+
"stddev": 260
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"name": "ancestors",
|
24
|
-
"ips":
|
25
|
-
"stddev":
|
24
|
+
"ips": 570.7095294720626,
|
25
|
+
"stddev": 86
|
26
26
|
},
|
27
27
|
{
|
28
28
|
"name": "descendants",
|
29
|
-
"ips": 0.
|
29
|
+
"ips": 0.17416664663106435,
|
30
30
|
"stddev": 0
|
31
31
|
}
|
32
32
|
]
|
data/bench/ancestry.json
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"name": "insertion",
|
4
|
-
"ips":
|
5
|
-
"stddev":
|
4
|
+
"ips": 1360.3315899162535,
|
5
|
+
"stddev": 117
|
6
6
|
},
|
7
7
|
{
|
8
8
|
"name": "parent",
|
9
|
-
"ips":
|
10
|
-
"stddev":
|
9
|
+
"ips": 1488.4291424270232,
|
10
|
+
"stddev": 132
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"name": "children",
|
14
|
-
"ips":
|
15
|
-
"stddev":
|
14
|
+
"ips": 10.612767367103928,
|
15
|
+
"stddev": 0
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"name": "roots",
|
19
|
-
"ips":
|
20
|
-
"stddev":
|
19
|
+
"ips": 2715.6226013175074,
|
20
|
+
"stddev": 380
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"name": "ancestors",
|
24
|
-
"ips":
|
25
|
-
"stddev":
|
24
|
+
"ips": 873.9805587004587,
|
25
|
+
"stddev": 228
|
26
26
|
},
|
27
27
|
{
|
28
28
|
"name": "descendants",
|
29
|
-
"ips":
|
30
|
-
"stddev":
|
29
|
+
"ips": 7.527704078159802,
|
30
|
+
"stddev": 1
|
31
31
|
}
|
32
32
|
]
|
@@ -1,32 +1,32 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"name": "insertion",
|
4
|
-
"ips":
|
5
|
-
"stddev":
|
4
|
+
"ips": 36.71486077897211,
|
5
|
+
"stddev": 6
|
6
6
|
},
|
7
7
|
{
|
8
8
|
"name": "parent",
|
9
|
-
"ips":
|
10
|
-
"stddev":
|
9
|
+
"ips": 1345.607177431047,
|
10
|
+
"stddev": 302
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"name": "children",
|
14
|
-
"ips":
|
15
|
-
"stddev":
|
14
|
+
"ips": 94.31692142141924,
|
15
|
+
"stddev": 18
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"name": "roots",
|
19
|
-
"ips":
|
20
|
-
"stddev":
|
19
|
+
"ips": 2093.0953165525248,
|
20
|
+
"stddev": 495
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"name": "ancestors",
|
24
|
-
"ips":
|
25
|
-
"stddev":
|
24
|
+
"ips": 747.8587257570059,
|
25
|
+
"stddev": 110
|
26
26
|
},
|
27
27
|
{
|
28
28
|
"name": "descendants",
|
29
|
-
"ips":
|
30
|
-
"stddev":
|
29
|
+
"ips": 64.8752595391903,
|
30
|
+
"stddev": 8
|
31
31
|
}
|
32
32
|
]
|
data/bench/benchmark.rb
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
gemfile(true) do
|
10
10
|
source 'https://rubygems.org'
|
11
11
|
gem 'activerecord', require: 'active_record'
|
12
|
-
gem '
|
12
|
+
gem 'sqlite3'
|
13
13
|
gem 'benchmark-ips'
|
14
14
|
|
15
15
|
case BENCH_GEM
|
@@ -25,8 +25,7 @@ gemfile(true) do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
ActiveRecord::Base.establish_connection(adapter: '
|
29
|
-
ActiveRecord::Base.connection.execute('DROP SCHEMA public CASCADE; CREATE SCHEMA public;')
|
28
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
30
29
|
|
31
30
|
ActiveRecord::Base.send(:include, ActsAsTree) if BENCH_GEM == 'acts_as_tree'
|
32
31
|
|
@@ -81,5 +80,5 @@ Benchmark.ips do |x|
|
|
81
80
|
x.report('descendants') do |times|
|
82
81
|
times.times { @comment1.reload.descendants.to_a }
|
83
82
|
end
|
84
|
-
x.json!("#{
|
83
|
+
x.json!("#{BENCH_GEM}.json")
|
85
84
|
end
|
data/bench/xylem.json
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
[
|
2
2
|
{
|
3
3
|
"name": "insertion",
|
4
|
-
"ips":
|
5
|
-
"stddev":
|
4
|
+
"ips": 1077.9540036082653,
|
5
|
+
"stddev": 181
|
6
6
|
},
|
7
7
|
{
|
8
8
|
"name": "parent",
|
9
|
-
"ips":
|
10
|
-
"stddev":
|
9
|
+
"ips": 1469.5468609459379,
|
10
|
+
"stddev": 153
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"name": "children",
|
14
|
-
"ips":
|
15
|
-
"stddev":
|
14
|
+
"ips": 5.6771757145767,
|
15
|
+
"stddev": 1
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"name": "roots",
|
19
|
-
"ips":
|
20
|
-
"stddev":
|
19
|
+
"ips": 2425.567017433215,
|
20
|
+
"stddev": 485
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"name": "ancestors",
|
24
|
-
"ips":
|
25
|
-
"stddev":
|
24
|
+
"ips": 950.0877817762773,
|
25
|
+
"stddev": 112
|
26
26
|
},
|
27
27
|
{
|
28
28
|
"name": "descendants",
|
29
|
-
"ips":
|
30
|
-
"stddev":
|
29
|
+
"ips": 8.066457306631666,
|
30
|
+
"stddev": 1
|
31
31
|
}
|
32
32
|
]
|
data/bootstrap.sh
CHANGED
@@ -6,14 +6,17 @@ function install {
|
|
6
6
|
}
|
7
7
|
|
8
8
|
echo updating package information
|
9
|
+
export DEBIAN_FRONTEND=noninteractive
|
10
|
+
curl -sSL "https://ftp-master.debian.org/keys/archive-key-7.0.asc" | sudo -E apt-key add -
|
11
|
+
echo "deb http://ftp.us.debian.org/debian unstable main contrib non-free" | sudo tee -a /etc/apt/sources.list > /dev/null
|
9
12
|
apt-add-repository -y ppa:brightbox/ruby-ng >/dev/null 2>&1
|
10
13
|
apt-get -y update >/dev/null 2>&1
|
11
14
|
|
12
15
|
install 'development tools' build-essential
|
13
16
|
|
14
|
-
install Ruby ruby2.
|
15
|
-
update-alternatives --set ruby /usr/bin/ruby2.
|
16
|
-
update-alternatives --set gem /usr/bin/gem2.
|
17
|
+
install Ruby ruby2.3 ruby2.3-dev
|
18
|
+
update-alternatives --set ruby /usr/bin/ruby2.3 >/dev/null 2>&1
|
19
|
+
update-alternatives --set gem /usr/bin/gem2.3 >/dev/null 2>&1
|
17
20
|
|
18
21
|
echo installing Bundler
|
19
22
|
gem install bundler -N >/dev/null 2>&1
|
data/gemfiles/ar_5beta.gemfile
CHANGED
data/lib/xylem/version.rb
CHANGED
data/lib/xylem.rb
CHANGED
data/test/xylem_tests.rb
CHANGED
@@ -223,4 +223,12 @@ class InstanceMethodsTest < XylemTestCase
|
|
223
223
|
refute @training.leaf?
|
224
224
|
refute @option1.leaf?
|
225
225
|
end
|
226
|
+
|
227
|
+
def test_leaves
|
228
|
+
assert_equal [@suboption11, @suboption12], @option1.leaves
|
229
|
+
assert_equal [@option3, @suboption11, @suboption12], @main.leaves
|
230
|
+
assert_equal [@physical, @digital], @product.leaves
|
231
|
+
assert_equal [@daily_training, @weekly_training], @training.leaves
|
232
|
+
assert_equal [@consultancy, @hosting, @daily_training, @weekly_training], @service.leaves
|
233
|
+
end
|
226
234
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xylem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Esgalha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
requirements: []
|
145
145
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.5.1
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Xylem uses the Adjacency List approach to store and query through hierarchical
|