tree_branch 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +24 -9
- data/README.md +6 -6
- data/lib/tree_branch/version.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/tree_branch/tree_branch_spec.rb +59 -57
- data/tree_branch.gemspec +3 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8473f9c14965c2a57e95f136405bb04e54bf0b3d724d583ed9016db22f51a3c7
|
4
|
+
data.tar.gz: 0706b615ecf17999274cedb975ba943eaf9b07021645f762ba899f8ee79bbed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a71be4ef99284701a9ab2c776beac29062bb874b197f000b8f9d8c24c74ba8464e840783e4300e1b8528f064e9ba3cea232e8554e0849147378c45d9028737d
|
7
|
+
data.tar.gz: 5560bc79fee28eed4570badba20ece7d269fd4b363f139f4fe6117292236739a711f9cf1d8666d5f634bd70e2ee8079895c0f21c44c208216936d7ad4fae62a6
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=3f49ba7a3ab8a835b5bba9f0932adaba5996dbffde7c098b20d52a3eaa833757
|
1
4
|
language: ruby
|
2
5
|
rvm:
|
3
|
-
# Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
|
4
|
-
- 2.3.8
|
5
|
-
- 2.4.5
|
6
|
-
- 2.5.3
|
7
|
-
- 2.6.0
|
6
|
+
# Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
|
7
|
+
- 2.3.8
|
8
|
+
- 2.4.5
|
9
|
+
- 2.5.3
|
10
|
+
- 2.6.0
|
8
11
|
cache: bundler
|
12
|
+
before_script:
|
13
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
14
|
+
- chmod +x ./cc-test-reporter
|
15
|
+
- ./cc-test-reporter before-build
|
9
16
|
script:
|
10
|
-
- bundle exec rubocop
|
11
|
-
- bundle exec rspec
|
17
|
+
- bundle exec rubocop
|
18
|
+
- bundle exec rspec
|
19
|
+
after_script:
|
20
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tree_branch (1.
|
4
|
+
tree_branch (1.1.0)
|
5
5
|
acts_as_hashable (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
acts_as_hashable (1.0.
|
10
|
+
acts_as_hashable (1.0.5)
|
11
|
+
ansi (1.5.0)
|
11
12
|
ast (2.4.0)
|
12
13
|
coderay (1.1.2)
|
13
14
|
diff-lcs (1.3)
|
15
|
+
docile (1.3.1)
|
14
16
|
ffi (1.9.25)
|
15
17
|
formatador (0.2.5)
|
16
18
|
guard (2.15.0)
|
@@ -27,7 +29,9 @@ GEM
|
|
27
29
|
guard (~> 2.1)
|
28
30
|
guard-compat (~> 1.1)
|
29
31
|
rspec (>= 2.99.0, < 4.0)
|
30
|
-
|
32
|
+
hirb (0.7.3)
|
33
|
+
jaro_winkler (1.5.2)
|
34
|
+
json (2.1.0)
|
31
35
|
listen (3.1.5)
|
32
36
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
33
37
|
rb-inotify (~> 0.9, >= 0.9.7)
|
@@ -38,8 +42,8 @@ GEM
|
|
38
42
|
notiffany (0.1.1)
|
39
43
|
nenv (~> 0.1)
|
40
44
|
shellany (~> 0.0)
|
41
|
-
parallel (1.
|
42
|
-
parser (2.
|
45
|
+
parallel (1.13.0)
|
46
|
+
parser (2.6.0.0)
|
43
47
|
ast (~> 2.4.0)
|
44
48
|
powerpack (0.1.2)
|
45
49
|
pry (0.12.2)
|
@@ -62,19 +66,28 @@ GEM
|
|
62
66
|
diff-lcs (>= 1.2.0, < 2.0)
|
63
67
|
rspec-support (~> 3.8.0)
|
64
68
|
rspec-support (3.8.0)
|
65
|
-
rubocop (0.
|
69
|
+
rubocop (0.63.1)
|
66
70
|
jaro_winkler (~> 1.5.1)
|
67
71
|
parallel (~> 1.10)
|
68
72
|
parser (>= 2.5, != 2.5.1.1)
|
69
73
|
powerpack (~> 0.1)
|
70
74
|
rainbow (>= 2.2.2, < 4.0)
|
71
75
|
ruby-progressbar (~> 1.7)
|
72
|
-
unicode-display_width (~> 1.
|
76
|
+
unicode-display_width (~> 1.4.0)
|
73
77
|
ruby-progressbar (1.10.0)
|
74
78
|
ruby_dep (1.5.0)
|
75
79
|
shellany (0.0.1)
|
80
|
+
simplecov (0.16.1)
|
81
|
+
docile (~> 1.1)
|
82
|
+
json (>= 1.8, < 3)
|
83
|
+
simplecov-html (~> 0.10.0)
|
84
|
+
simplecov-console (0.4.2)
|
85
|
+
ansi
|
86
|
+
hirb
|
87
|
+
simplecov
|
88
|
+
simplecov-html (0.10.2)
|
76
89
|
thor (0.20.3)
|
77
|
-
unicode-display_width (1.4.
|
90
|
+
unicode-display_width (1.4.1)
|
78
91
|
|
79
92
|
PLATFORMS
|
80
93
|
ruby
|
@@ -82,7 +95,9 @@ PLATFORMS
|
|
82
95
|
DEPENDENCIES
|
83
96
|
guard-rspec (~> 4.7)
|
84
97
|
rspec (~> 3.8)
|
85
|
-
rubocop (~> 0.
|
98
|
+
rubocop (~> 0.63.1)
|
99
|
+
simplecov (~> 0.16.1)
|
100
|
+
simplecov-console (~> 0.4.2)
|
86
101
|
tree_branch!
|
87
102
|
|
88
103
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# TreeBranch
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/bluemarblepayroll/tree_branch.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/tree_branch)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tree_branch.svg)](https://badge.fury.io/rb/tree_branch) [![Build Status](https://travis-ci.org/bluemarblepayroll/tree_branch.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/tree_branch) [![Maintainability](https://api.codeclimate.com/v1/badges/9875bbc4672509465601/maintainability)](https://codeclimate.com/github/bluemarblepayroll/tree_branch/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/9875bbc4672509465601/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/tree_branch/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
4
4
|
|
5
5
|
This library allows you to traverse an entire tree structure, compare all nodes, and choose a tree structure to return. The basic input is defined as:
|
6
6
|
|
@@ -417,12 +417,12 @@ Note: ensure you have proper authorization before trying to publish new versions
|
|
417
417
|
After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
|
418
418
|
|
419
419
|
1. Merge Pull Request into master
|
420
|
-
2. Update
|
421
|
-
3.
|
422
|
-
4. Update CHANGELOG.md
|
423
|
-
5. Commit &
|
420
|
+
2. Update ```lib/tree_branch/version.rb``` using [semantic versioning](https://semver.org/)
|
421
|
+
3. Install dependencies: ```bundle```
|
422
|
+
4. Update ```CHANGELOG.md``` with release notes
|
423
|
+
5. Commit & push master to remote and ensure CI builds master successfully
|
424
424
|
6. Build the project locally: `gem build tree_branch`
|
425
|
-
7. Publish package to
|
425
|
+
7. Publish package to RubyGems: `gem push tree_branch-X.gem` where X is the version to push
|
426
426
|
8. Tag master with new version: `git tag <version>`
|
427
427
|
9. Push tags remotely: `git push origin --tags`
|
428
428
|
|
data/lib/tree_branch/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,57 @@
|
|
9
9
|
|
10
10
|
require './spec/spec_helper'
|
11
11
|
|
12
|
+
require 'pry'
|
13
|
+
|
14
|
+
class MenuItem
|
15
|
+
acts_as_hashable
|
16
|
+
|
17
|
+
attr_reader :menu_items, :name
|
18
|
+
|
19
|
+
def initialize(name: '', menu_items: [])
|
20
|
+
@name = name
|
21
|
+
@menu_items = self.class.array(menu_items)
|
22
|
+
end
|
23
|
+
|
24
|
+
def eql?(other)
|
25
|
+
name == other.name && menu_items == other.menu_items
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
eql?(other)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class BornAfter1915 < ::TreeBranch::Comparator
|
34
|
+
def valid?
|
35
|
+
Date.parse(data.dob).year > 1915
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class NameStartsWith < ::TreeBranch::Comparator
|
40
|
+
def valid?
|
41
|
+
context[:letters].include?(data.name.to_s[0])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class StateComparator < ::TreeBranch::Comparator
|
46
|
+
STATE_OPS = {
|
47
|
+
none: %i[open],
|
48
|
+
passive: %i[open save close print],
|
49
|
+
active: %i[open save close print cut copy paste]
|
50
|
+
}.freeze
|
51
|
+
|
52
|
+
def valid?
|
53
|
+
data.command.nil? || Array(STATE_OPS[context[:state]]).include?(data.command)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class AuthorizationComparator < ::TreeBranch::Comparator
|
58
|
+
def valid?
|
59
|
+
data.right.nil? || Array(context[:rights]).include?(data.right)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
12
63
|
describe ::TreeBranch do
|
13
64
|
# We will use this spec to also test ::TreeBranch::Node#process since ::TreeBranch#process
|
14
65
|
# fully delegates to that method.
|
@@ -33,18 +84,6 @@ describe ::TreeBranch do
|
|
33
84
|
::TreeBranch::SimpleNode.make(born_after1915_starts_with_m_or_s_hash)
|
34
85
|
end
|
35
86
|
|
36
|
-
class BornAfter1915 < ::TreeBranch::Comparator
|
37
|
-
def valid?
|
38
|
-
Date.parse(data.dob).year > 1915
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class NameStartsWith < ::TreeBranch::Comparator
|
43
|
-
def valid?
|
44
|
-
context[:letters].include?(data.name.to_s[0])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
87
|
let(:name_starts_with_lambda) do
|
49
88
|
lambda do |data, context|
|
50
89
|
context.letters.include?(data.name.to_s[0])
|
@@ -68,9 +107,9 @@ describe ::TreeBranch do
|
|
68
107
|
|
69
108
|
it 'should return valid nodes with two class comparators' do
|
70
109
|
input = {
|
71
|
-
node:
|
72
|
-
context:
|
73
|
-
comparators:
|
110
|
+
node: node_hash,
|
111
|
+
context: { letters: %w[M S] },
|
112
|
+
comparators: [BornAfter1915, NameStartsWith]
|
74
113
|
}
|
75
114
|
|
76
115
|
expect(::TreeBranch.process(input)).to eq(born_after1915_starts_with_m_or_s)
|
@@ -78,9 +117,9 @@ describe ::TreeBranch do
|
|
78
117
|
|
79
118
|
it 'should return valid nodes with one class comparator and one lambda comparator' do
|
80
119
|
input = {
|
81
|
-
node:
|
82
|
-
context:
|
83
|
-
comparators:
|
120
|
+
node: node_hash,
|
121
|
+
context: { letters: %w[M S] },
|
122
|
+
comparators: [BornAfter1915, name_starts_with_lambda]
|
84
123
|
}
|
85
124
|
|
86
125
|
expect(::TreeBranch.process(input)).to eq(born_after1915_starts_with_m_or_s)
|
@@ -90,8 +129,8 @@ describe ::TreeBranch do
|
|
90
129
|
outside_variable = '!!'
|
91
130
|
|
92
131
|
input = {
|
93
|
-
node:
|
94
|
-
context:
|
132
|
+
node: node,
|
133
|
+
context: OpenStruct.new(suffix: 'cakes')
|
95
134
|
}
|
96
135
|
|
97
136
|
processed = ::TreeBranch.process(input) do |data, children, context|
|
@@ -107,18 +146,6 @@ describe ::TreeBranch do
|
|
107
146
|
end
|
108
147
|
|
109
148
|
describe 'README Examples' do
|
110
|
-
class StateComparator < ::TreeBranch::Comparator
|
111
|
-
STATE_OPS = {
|
112
|
-
none: %i[open],
|
113
|
-
passive: %i[open save close print],
|
114
|
-
active: %i[open save close print cut copy paste]
|
115
|
-
}.freeze
|
116
|
-
|
117
|
-
def valid?
|
118
|
-
data.command.nil? || Array(STATE_OPS[context[:state]]).include?(data.command)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
149
|
let(:menu) do
|
123
150
|
{
|
124
151
|
data: { name: 'Menu' },
|
@@ -254,12 +281,6 @@ describe ::TreeBranch do
|
|
254
281
|
expect(no_file_menu).to eq(expected)
|
255
282
|
end
|
256
283
|
|
257
|
-
class AuthorizationComparator < ::TreeBranch::Comparator
|
258
|
-
def valid?
|
259
|
-
data.right.nil? || Array(context[:rights]).include?(data.right)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
284
|
it 'should compute state: passive for read-only authorization' do
|
264
285
|
no_file_menu = ::TreeBranch.process(
|
265
286
|
node: menu,
|
@@ -337,25 +358,6 @@ describe ::TreeBranch do
|
|
337
358
|
end
|
338
359
|
end
|
339
360
|
|
340
|
-
class MenuItem
|
341
|
-
acts_as_hashable
|
342
|
-
|
343
|
-
attr_reader :menu_items, :name
|
344
|
-
|
345
|
-
def initialize(name: '', menu_items: [])
|
346
|
-
@name = name
|
347
|
-
@menu_items = self.class.array(menu_items)
|
348
|
-
end
|
349
|
-
|
350
|
-
def eql?(other)
|
351
|
-
name == other.name && menu_items == other.menu_items
|
352
|
-
end
|
353
|
-
|
354
|
-
def ==(other)
|
355
|
-
eql?(other)
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
361
|
it 'should compute state: passive for read/write authorization and return MenuItem(s)' do
|
360
362
|
passive_read_write_menu =
|
361
363
|
::TreeBranch.process(
|
data/tree_branch.gemspec
CHANGED
@@ -25,5 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_development_dependency('guard-rspec', '~>4.7')
|
27
27
|
s.add_development_dependency('rspec', '~> 3.8')
|
28
|
-
s.add_development_dependency('rubocop', '~>
|
28
|
+
s.add_development_dependency('rubocop', '~>0.63.1')
|
29
|
+
s.add_development_dependency('simplecov', '~>0.16.1')
|
30
|
+
s.add_development_dependency('simplecov-console', '~>0.4.2')
|
29
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tree_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_hashable
|
@@ -58,14 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.63.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.63.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.16.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.16.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov-console
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.4.2
|
69
97
|
description: " This library allows you to input a tree structure (node with children),
|
70
98
|
a context, and comparators then outputs you the matching tree structure.\n"
|
71
99
|
email:
|