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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f36a0a448ea0f87bbb5bb18b7ebb4f090e8a724
4
- data.tar.gz: 74c92b1a1d23c3524480c3c97521f5f1bf3395b7
3
+ metadata.gz: a66a285e5aacfa913b065f184b825218e6cfa07d
4
+ data.tar.gz: 7edc791c60d6c1638c460c2975a125ac746af45a
5
5
  SHA512:
6
- metadata.gz: 25b9ac95f3a6c51d2abc5195269a7f6bab89376dffb32034db0a9aad18cf52974083ac5666515cdd0ebb6d93b77f68c80d1253ff256a4900e271ab99f6aec9b3
7
- data.tar.gz: 9406bb0aec116ecee01b8f7dfdd3c5e3f190580eba20afb2f8e3a2a0fe57b81b4a23aa1d2d68889ed92fdd7adf6f2e982d55cf9429d223bfb7f9c9e57ad962c1
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', github: 'oesgalha/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 or model by adding the `acts_as_tree` directive in it.
52
- Let's suppose again that you're dealing with a model called `Menu`, you should add the following:
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 from the node, excluding itself.
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
@@ -5,4 +5,10 @@ task :test do
5
5
  require './test/xylem_tests.rb'
6
6
  end
7
7
 
8
+ task :bench do
9
+ ['acts_as_tree', 'ancestry', 'awesome_nested_set', 'xylem'].each do |benched_gem|
10
+ sh "cd bench/ && BENCH_GEM=#{benched_gem} ruby benchmark.rb"
11
+ end
12
+ end
13
+
8
14
  task default: :test
@@ -1,32 +1,32 @@
1
1
  [
2
2
  {
3
3
  "name": "insertion",
4
- "ips": 412.7091261183738,
5
- "stddev": 51
4
+ "ips": 1036.8914832940068,
5
+ "stddev": 195
6
6
  },
7
7
  {
8
8
  "name": "parent",
9
- "ips": 633.857043437574,
10
- "stddev": 85
9
+ "ips": 1215.4998688546427,
10
+ "stddev": 252
11
11
  },
12
12
  {
13
13
  "name": "children",
14
- "ips": 8.660125142509473,
15
- "stddev": 2
14
+ "ips": 5.281724863837879,
15
+ "stddev": 1
16
16
  },
17
17
  {
18
18
  "name": "roots",
19
- "ips": 1029.8556860775493,
20
- "stddev": 136
19
+ "ips": 2607.3692118170793,
20
+ "stddev": 260
21
21
  },
22
22
  {
23
23
  "name": "ancestors",
24
- "ips": 251.68388495529973,
25
- "stddev": 33
24
+ "ips": 570.7095294720626,
25
+ "stddev": 86
26
26
  },
27
27
  {
28
28
  "name": "descendants",
29
- "ips": 0.19643176694334188,
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": 529.3829399001362,
5
- "stddev": 68
4
+ "ips": 1360.3315899162535,
5
+ "stddev": 117
6
6
  },
7
7
  {
8
8
  "name": "parent",
9
- "ips": 798.8413756182359,
10
- "stddev": 112
9
+ "ips": 1488.4291424270232,
10
+ "stddev": 132
11
11
  },
12
12
  {
13
13
  "name": "children",
14
- "ips": 19.534339432833036,
15
- "stddev": 2
14
+ "ips": 10.612767367103928,
15
+ "stddev": 0
16
16
  },
17
17
  {
18
18
  "name": "roots",
19
- "ips": 1306.76576446662,
20
- "stddev": 254
19
+ "ips": 2715.6226013175074,
20
+ "stddev": 380
21
21
  },
22
22
  {
23
23
  "name": "ancestors",
24
- "ips": 501.12099359692917,
25
- "stddev": 112
24
+ "ips": 873.9805587004587,
25
+ "stddev": 228
26
26
  },
27
27
  {
28
28
  "name": "descendants",
29
- "ips": 14.539749441549349,
30
- "stddev": 2
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": 7.721853007625269,
5
- "stddev": 2
4
+ "ips": 36.71486077897211,
5
+ "stddev": 6
6
6
  },
7
7
  {
8
8
  "name": "parent",
9
- "ips": 569.4524509694182,
10
- "stddev": 191
9
+ "ips": 1345.607177431047,
10
+ "stddev": 302
11
11
  },
12
12
  {
13
13
  "name": "children",
14
- "ips": 154.39379306573127,
15
- "stddev": 34
14
+ "ips": 94.31692142141924,
15
+ "stddev": 18
16
16
  },
17
17
  {
18
18
  "name": "roots",
19
- "ips": 820.8230612972056,
20
- "stddev": 119
19
+ "ips": 2093.0953165525248,
20
+ "stddev": 495
21
21
  },
22
22
  {
23
23
  "name": "ancestors",
24
- "ips": 346.3686578783685,
25
- "stddev": 70
24
+ "ips": 747.8587257570059,
25
+ "stddev": 110
26
26
  },
27
27
  {
28
28
  "name": "descendants",
29
- "ips": 52.86002694684352,
30
- "stddev": 7
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 'pg'
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: 'postgresql', database: 'xylem_test', username: 'postgres')
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!("#{ENV['BENCH_GEM']}.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": 600.964555391788,
5
- "stddev": 34
4
+ "ips": 1077.9540036082653,
5
+ "stddev": 181
6
6
  },
7
7
  {
8
8
  "name": "parent",
9
- "ips": 1070.2536522884402,
10
- "stddev": 120
9
+ "ips": 1469.5468609459379,
10
+ "stddev": 153
11
11
  },
12
12
  {
13
13
  "name": "children",
14
- "ips": 11.90851991649796,
15
- "stddev": 2
14
+ "ips": 5.6771757145767,
15
+ "stddev": 1
16
16
  },
17
17
  {
18
18
  "name": "roots",
19
- "ips": 1713.3724759018537,
20
- "stddev": 210
19
+ "ips": 2425.567017433215,
20
+ "stddev": 485
21
21
  },
22
22
  {
23
23
  "name": "ancestors",
24
- "ips": 511.49023662770406,
25
- "stddev": 61
24
+ "ips": 950.0877817762773,
25
+ "stddev": 112
26
26
  },
27
27
  {
28
28
  "name": "descendants",
29
- "ips": 12.000439734178782,
30
- "stddev": 2
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.2 ruby2.2-dev
15
- update-alternatives --set ruby /usr/bin/ruby2.2 >/dev/null 2>&1
16
- update-alternatives --set gem /usr/bin/gem2.2 >/dev/null 2>&1
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
@@ -4,6 +4,6 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "codeclimate-test-reporter", :group => :test, :require => nil
6
6
  gem "appraisal"
7
- gem "activerecord", "5.0.0.beta1"
7
+ gem "activerecord", "5.0.0.rc1"
8
8
 
9
9
  gemspec :path => "../"
data/lib/xylem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xylem
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/xylem.rb CHANGED
@@ -42,6 +42,10 @@ module Xylem
42
42
  children.size == 0
43
43
  end
44
44
 
45
+ def leaves
46
+ descendants.leaves
47
+ end
48
+
45
49
  private
46
50
 
47
51
  def _xylem_query(where_col, where_val, join_lft_col, join_rgt_col, order_stmt)
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.1
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-01-18 00:00:00.000000000 Z
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.4.5
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