tree_branch 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8473f9c14965c2a57e95f136405bb04e54bf0b3d724d583ed9016db22f51a3c7
4
- data.tar.gz: 0706b615ecf17999274cedb975ba943eaf9b07021645f762ba899f8ee79bbed7
3
+ metadata.gz: 295f232a71033c42f3fa2eede7a9f78637a9b1a2b8ca165f92a2cfe67f92c10a
4
+ data.tar.gz: 611148e278d08ab9bd90277ff04c4a1239a5faca97cb2d9a669a622e362354bd
5
5
  SHA512:
6
- metadata.gz: 9a71be4ef99284701a9ab2c776beac29062bb874b197f000b8f9d8c24c74ba8464e840783e4300e1b8528f064e9ba3cea232e8554e0849147378c45d9028737d
7
- data.tar.gz: 5560bc79fee28eed4570badba20ece7d269fd4b363f139f4fe6117292236739a711f9cf1d8666d5f634bd70e2ee8079895c0f21c44c208216936d7ad4fae62a6
6
+ metadata.gz: afe8a2a94158b18b76fb3c2a7021769c57ed607967a523e73c41b999b7ea3c5d7dbbc695ae48087d5abc76687c449b802e11fb0652a094cc47685a3e7b2e3998
7
+ data.tar.gz: 745fa57dacae0336f5f9fd312c53e65aa4a7b5312f706409c076c6b2a0d23b398e10962dc959b9a5c2a86d7dd5fe56d54b3f562d2a624cdc13b3f3ffa321252c
data/.gitignore CHANGED
@@ -2,3 +2,6 @@
2
2
  *.gem
3
3
  /tmp
4
4
  /coverage
5
+
6
+ # https://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
7
+ Gemfile.lock
@@ -1 +1 @@
1
- 2.6.0
1
+ 2.6.3
@@ -5,9 +5,9 @@ language: ruby
5
5
  rvm:
6
6
  # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
7
7
  - 2.3.8
8
- - 2.4.5
9
- - 2.5.3
10
- - 2.6.0
8
+ - 2.4.6
9
+ - 2.5.5
10
+ - 2.6.3
11
11
  cache: bundler
12
12
  before_script:
13
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
@@ -18,3 +18,8 @@ script:
18
18
  - bundle exec rspec
19
19
  after_script:
20
20
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
+ addons:
22
+ # https://docs.travis-ci.com/user/uploading-artifacts/
23
+ artifacts:
24
+ paths:
25
+ - Gemfile.lock
@@ -1,6 +1,16 @@
1
+ # 1.0.1 (June 28th, 2019)
2
+
3
+ Maintenance Release
4
+
5
+ * Fixed a Readme bug where the StateComparator example incorrectly referenced context as an object instead of a Hash.
6
+ * Other minor README.md changes to improve clarity.
7
+ * Updated Ruby versions used for testing.
8
+ * Added a default Rake task to run all checks.
9
+ * Removed Gemfile.lock from version control.
10
+
1
11
  # 1.1.0 (February 5th, 2019)
2
12
 
3
- Maintance Release
13
+ Maintenance Release
4
14
 
5
15
  * Updated Dependencies
6
16
  * Installed SimpleCov
data/README.md CHANGED
@@ -12,7 +12,7 @@ And the output is defined as:
12
12
 
13
13
  1. Compared and/or converted tree structure (root node)
14
14
 
15
- The specific use-case this was designed for was a dynamic web application menu. In this specific example, we wanted either a static file or a database to store and define all possible menus. Then we wanted to input a request's lifecycle context (user, url, parameters, authorization, etc.) and return the menu that matched the current spot in the application.
15
+ The specific use-case this was designed for was a dynamic web application menu. In this specific example, we wanted either a static file or a database to store and define all possible menus. Then we wanted to input a request's lifecycle context (user, URL, parameters, authorization, etc.) and return the menu that matched the current spot in the application.
16
16
 
17
17
  ## Installation
18
18
 
@@ -62,7 +62,7 @@ menu = {
62
62
  ]
63
63
  }
64
64
  ]
65
- }
65
+ }.freeze
66
66
  ````
67
67
 
68
68
  There are three application states:
@@ -85,10 +85,11 @@ class StateComparator < ::TreeBranch::Comparator
85
85
  none: %i[open],
86
86
  passive: %i[open save close print],
87
87
  active: %i[open save close print cut copy paste]
88
- }
88
+ }.freeze
89
+ private_constant :STATE_OPS
89
90
 
90
91
  def valid?
91
- data.command.nil? || Array(STATE_OPS[context.state]).include?(data.command)
92
+ data.command.nil? || Array(STATE_OPS[context[:state]]).include?(data.command)
92
93
  end
93
94
  end
94
95
  ````
@@ -97,21 +98,21 @@ Finally, we can process this for all three states:
97
98
 
98
99
  ````ruby
99
100
  no_file_menu =
100
- ::TreeBranch.process(
101
+ TreeBranch.process(
101
102
  node: menu,
102
103
  comparators: StateComparator,
103
104
  context: { state: :none }
104
105
  )
105
106
 
106
107
  passive_file_menu =
107
- ::TreeBranch.process(
108
+ TreeBranch.process(
108
109
  node: menu,
109
110
  comparators: StateComparator,
110
111
  context: { state: :passive }
111
112
  )
112
113
 
113
114
  active_file_menu =
114
- ::TreeBranch.process(
115
+ TreeBranch.process(
115
116
  node: menu,
116
117
  comparators: StateComparator,
117
118
  context: { state: :active }
@@ -291,8 +292,8 @@ Notice now our read-only menu is missing the 'save' item.
291
292
 
292
293
  There are two ways to create comparators:
293
294
 
294
- 1. Subclass ::TreeBranch::Comparator and implement the ```valid?``` method to return true/false
295
- 2. Create lambda/proc that accepts two arguments: data and context and returns true/false
295
+ 1. Subclass ::TreeBranch::Comparator and implement the ```valid?``` method to return true/false.
296
+ 2. Create lambda/proc that accepts two arguments: data and context and returns true/false.
296
297
 
297
298
  Option one is shown in the above example, while option two can be illustrated as:
298
299
 
@@ -302,7 +303,7 @@ auth_comparator = lambda do |data, context|
302
303
  end
303
304
 
304
305
  passive_read_only_menu =
305
- ::TreeBranch.process(
306
+ TreeBranch.process(
306
307
  node: menu,
307
308
  comparators: [StateComparator, auth_comparator],
308
309
  context: { state: :passive }
@@ -313,14 +314,14 @@ passive_read_only_menu =
313
314
 
314
315
  After a node has been compared and is deemed to be valid, it will either return one of two things:
315
316
 
316
- 1. ::TreeBranch::Node instance
317
- 2. The return of the block passed into the process method produced *(Note: If nil it will be ignored as if it was invalid.)*
317
+ 1. A `TreeBranch::Node` instance.
318
+ 2. The return value of the block passed into the process method. *Note: If the block returns `nil` then it will be ignored as if it was invalid.*
318
319
 
319
- In our above example we did not pass in a block so they would all return Node instances. The passed in block is your chance to return instances of another class, or even do some other post-processing routines. For example, lets return an instance of a new type: MenuItem as shown below:
320
+ In our above example, we did not pass in a block so they would all return Node instances. The passed in block is your chance to return instances of another class, or even do some other post-processing routines. For example, lets return an instance of a new type: MenuItem as shown below:
320
321
 
321
322
  ````ruby
322
323
  class MenuItem
323
- acts_as_hashable
324
+ acts_as_hashable # Provided by https://github.com/bluemarblepayroll/acts_as_hashable
324
325
 
325
326
  attr_reader :menu_items, :name
326
327
 
@@ -333,9 +334,7 @@ class MenuItem
333
334
  name == other.name && menu_items == other.menu_items
334
335
  end
335
336
 
336
- def ==(other)
337
- eql?(other)
338
- end
337
+ alias == eql?
339
338
  end
340
339
  ````
341
340
 
@@ -343,7 +342,7 @@ We can now convert this in the block:
343
342
 
344
343
  ````ruby
345
344
  passive_read_write_menu =
346
- ::TreeBranch.process(
345
+ TreeBranch.process(
347
346
  node: menu,
348
347
  comparators: [StateComparator, auth_comparator],
349
348
  context: { state: :passive, rights: :write }
@@ -385,10 +384,10 @@ Our resulting data set (visualized as a hash):
385
384
  Basic steps to take to get this repository compiling:
386
385
 
387
386
  1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (check tree_branch.gemspec for versions supported)
388
- 2. Install bundler (gem install bundler)
389
- 3. Clone the repository (git clone git@github.com:bluemarblepayroll/tree_branch.git)
390
- 4. Navigate to the root folder (cd tree_branch)
391
- 5. Install dependencies (bundle)
387
+ 2. Install bundler (`gem install bundler`)
388
+ 3. Clone the repository (`git clone git@github.com:bluemarblepayroll/tree_branch.git`)
389
+ 4. Navigate to the root folder (`cd tree_branch`)
390
+ 5. Install dependencies (`bundle`)
392
391
 
393
392
  ### Running Tests
394
393
 
@@ -410,6 +409,12 @@ Also, do not forget to run Rubocop:
410
409
  bundle exec rubocop
411
410
  ````
412
411
 
412
+ Note that the default Rake tasks runs both test and Rubocop:
413
+
414
+ ```
415
+ bundle exec rake
416
+ ```
417
+
413
418
  ### Publishing
414
419
 
415
420
  Note: ensure you have proper authorization before trying to publish new versions.
@@ -417,14 +422,13 @@ Note: ensure you have proper authorization before trying to publish new versions
417
422
  After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
418
423
 
419
424
  1. Merge Pull Request into master
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
425
+ 2. Update `lib/tree_branch/version.rb` using [semantic versioning](https://semver.org/)
426
+ 3. Install dependencies: `bundle`
427
+ 4. Update `CHANGELOG.md` with release notes
423
428
  5. Commit & push master to remote and ensure CI builds master successfully
424
- 6. Build the project locally: `gem build tree_branch`
425
- 7. Publish package to RubyGems: `gem push tree_branch-X.gem` where X is the version to push
426
- 8. Tag master with new version: `git tag <version>`
427
- 9. Push tags remotely: `git push origin --tags`
429
+ 6. Run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
430
+
431
+ Note: ensure you have proper authorization before trying to publish new versions.
428
432
 
429
433
  ## License
430
434
 
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[rubocop spec]
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module TreeBranch
11
- VERSION = '1.1.0'
11
+ VERSION = '1.1.1'
12
12
  end
@@ -19,11 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.homepage = 'https://github.com/bluemarblepayroll/tree_branch'
20
20
  s.license = 'MIT'
21
21
 
22
- s.required_ruby_version = '>= 2.3.1'
22
+ s.required_ruby_version = '>= 2.3.8'
23
23
 
24
24
  s.add_dependency('acts_as_hashable', '~>1.0')
25
25
 
26
26
  s.add_development_dependency('guard-rspec', '~>4.7')
27
+ s.add_development_dependency('pry')
28
+ s.add_development_dependency('pry-byebug')
29
+ s.add_development_dependency('rake', '~> 12')
27
30
  s.add_development_dependency('rspec', '~> 3.8')
28
31
  s.add_development_dependency('rubocop', '~>0.63.1')
29
32
  s.add_development_dependency('simplecov', '~>0.16.1')
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.1.0
4
+ version: 1.1.1
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-02-05 00:00:00.000000000 Z
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: acts_as_hashable
@@ -38,6 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: rspec
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -110,10 +152,10 @@ files:
110
152
  - ".travis.yml"
111
153
  - CHANGELOG.md
112
154
  - Gemfile
113
- - Gemfile.lock
114
155
  - Guardfile
115
156
  - LICENSE
116
157
  - README.md
158
+ - Rakefile
117
159
  - bin/console
118
160
  - lib/tree_branch.rb
119
161
  - lib/tree_branch/comparator.rb
@@ -143,14 +185,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
185
  requirements:
144
186
  - - ">="
145
187
  - !ruby/object:Gem::Version
146
- version: 2.3.1
188
+ version: 2.3.8
147
189
  required_rubygems_version: !ruby/object:Gem::Requirement
148
190
  requirements:
149
191
  - - ">="
150
192
  - !ruby/object:Gem::Version
151
193
  version: '0'
152
194
  requirements: []
153
- rubygems_version: 3.0.1
195
+ rubygems_version: 3.0.3
154
196
  signing_key:
155
197
  specification_version: 4
156
198
  summary: Compare a tree structure and return the tree structure that matches
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- tree_branch (1.1.0)
5
- acts_as_hashable (~> 1.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- acts_as_hashable (1.0.5)
11
- ansi (1.5.0)
12
- ast (2.4.0)
13
- coderay (1.1.2)
14
- diff-lcs (1.3)
15
- docile (1.3.1)
16
- ffi (1.9.25)
17
- formatador (0.2.5)
18
- guard (2.15.0)
19
- formatador (>= 0.2.4)
20
- listen (>= 2.7, < 4.0)
21
- lumberjack (>= 1.0.12, < 2.0)
22
- nenv (~> 0.1)
23
- notiffany (~> 0.0)
24
- pry (>= 0.9.12)
25
- shellany (~> 0.0)
26
- thor (>= 0.18.1)
27
- guard-compat (1.2.1)
28
- guard-rspec (4.7.3)
29
- guard (~> 2.1)
30
- guard-compat (~> 1.1)
31
- rspec (>= 2.99.0, < 4.0)
32
- hirb (0.7.3)
33
- jaro_winkler (1.5.2)
34
- json (2.1.0)
35
- listen (3.1.5)
36
- rb-fsevent (~> 0.9, >= 0.9.4)
37
- rb-inotify (~> 0.9, >= 0.9.7)
38
- ruby_dep (~> 1.2)
39
- lumberjack (1.0.13)
40
- method_source (0.9.2)
41
- nenv (0.3.0)
42
- notiffany (0.1.1)
43
- nenv (~> 0.1)
44
- shellany (~> 0.0)
45
- parallel (1.13.0)
46
- parser (2.6.0.0)
47
- ast (~> 2.4.0)
48
- powerpack (0.1.2)
49
- pry (0.12.2)
50
- coderay (~> 1.1.0)
51
- method_source (~> 0.9.0)
52
- rainbow (3.0.0)
53
- rb-fsevent (0.10.3)
54
- rb-inotify (0.9.10)
55
- ffi (>= 0.5.0, < 2)
56
- rspec (3.8.0)
57
- rspec-core (~> 3.8.0)
58
- rspec-expectations (~> 3.8.0)
59
- rspec-mocks (~> 3.8.0)
60
- rspec-core (3.8.0)
61
- rspec-support (~> 3.8.0)
62
- rspec-expectations (3.8.2)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.8.0)
65
- rspec-mocks (3.8.0)
66
- diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.8.0)
68
- rspec-support (3.8.0)
69
- rubocop (0.63.1)
70
- jaro_winkler (~> 1.5.1)
71
- parallel (~> 1.10)
72
- parser (>= 2.5, != 2.5.1.1)
73
- powerpack (~> 0.1)
74
- rainbow (>= 2.2.2, < 4.0)
75
- ruby-progressbar (~> 1.7)
76
- unicode-display_width (~> 1.4.0)
77
- ruby-progressbar (1.10.0)
78
- ruby_dep (1.5.0)
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)
89
- thor (0.20.3)
90
- unicode-display_width (1.4.1)
91
-
92
- PLATFORMS
93
- ruby
94
-
95
- DEPENDENCIES
96
- guard-rspec (~> 4.7)
97
- rspec (~> 3.8)
98
- rubocop (~> 0.63.1)
99
- simplecov (~> 0.16.1)
100
- simplecov-console (~> 0.4.2)
101
- tree_branch!
102
-
103
- BUNDLED WITH
104
- 1.17.2