except_nested 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: ce8d61447e18525bc6d98dae31ffe737eb4d8882
4
- data.tar.gz: fbceed209c89579f5ab75a507920a947b796018d
2
+ SHA256:
3
+ metadata.gz: a76dcea382a186cc384dbb576231e0b701a4e01145d024bace65b9e1d4a8a7b9
4
+ data.tar.gz: 9c60fc75b2a1f5eca30d634f2863b755ecd324cba5a26698888cd6a8d04505e6
5
5
  SHA512:
6
- metadata.gz: bd6da6fecdf470ff9eb8bb0e28346b5cae692121d6e594cbb60a8c3411fa9537c4ec36bd62f2f099142f6052a8f161c6db281b88d29669999079ba29c12d320b
7
- data.tar.gz: 7033a86553ebc7698351cab2bd198b67c8fe47dddb632545ecf24cea0680bb58c61f38025a4d86e5883e99966a7b50cbf642c948a13cbe170e9b19f851daab1a
6
+ metadata.gz: 66df5e47a6d5c1bd1dadfa86f49d9e6d7645e33381fc323de7eafb126ba3c5ffeb7a936a80565632110438238bfef7a05ea342520182d62833ee59c4e245293f
7
+ data.tar.gz: 5a2d558f97f28281c612dfce45e9bf648d896b1db7939fd70d7192fab39a2608e9cc61b150c73d9400a62d52e07bfe33b71ea9d381d753826387484243503c0c
data/.gitignore CHANGED
@@ -1,12 +1,38 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
1
+ # Created by https://www.gitignore.io/api/ruby
2
+
3
+ ### Ruby ###
4
+ *.gem
5
+ *.rbc
6
+ /.config
5
7
  /coverage/
6
- /doc/
8
+ /InstalledFiles
7
9
  /pkg/
8
10
  /spec/reports/
11
+ /spec/examples.txt
12
+ /test/tmp/
13
+ /test/version_tmp/
9
14
  /tmp/
10
15
 
11
- # rspec failure tracking
12
- .rspec_status
16
+ # Used by dotenv library to load environment variables.
17
+ # .env
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
31
+ .rvmrc
32
+
33
+ # End of https://www.gitignore.io/api/ruby
34
+
35
+ # Ignore publish script due to credentials
36
+ .publish
37
+
38
+ codeclimate-test-reporter
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.5.5
data/.travis.yml CHANGED
@@ -1,8 +1,16 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.2
5
- - 2.3.0
6
- - 2.4.0
7
- - 2.4.1
8
- before_install: gem install bundler -v 1.15.3
4
+ - 2.5.0
5
+ - 2.6.0
6
+ - 2.7.0
7
+ before_install: gem install bundler -v 2.2.20
8
+ install: bundle install --jobs=3 --retry=3
9
+ before_script:
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - ./cc-test-reporter before-build
13
+ script:
14
+ - bundle exec rspec
15
+ after_script:
16
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ except_nested (0.1.3)
5
+ activesupport (~> 6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.4)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ codeclimate-test-reporter (1.0.7)
17
+ simplecov
18
+ concurrent-ruby (1.1.9)
19
+ diff-lcs (1.4.4)
20
+ docile (1.4.0)
21
+ i18n (1.8.10)
22
+ concurrent-ruby (~> 1.0)
23
+ minitest (5.14.4)
24
+ rake (13.0.6)
25
+ rspec (3.10.0)
26
+ rspec-core (~> 3.10.0)
27
+ rspec-expectations (~> 3.10.0)
28
+ rspec-mocks (~> 3.10.0)
29
+ rspec-core (3.10.1)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-expectations (3.10.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-mocks (3.10.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-support (3.10.2)
38
+ simplecov (0.21.2)
39
+ docile (~> 1.1)
40
+ simplecov-html (~> 0.11)
41
+ simplecov_json_formatter (~> 0.1)
42
+ simplecov-html (0.12.3)
43
+ simplecov_json_formatter (0.1.3)
44
+ tzinfo (2.0.4)
45
+ concurrent-ruby (~> 1.0)
46
+ zeitwerk (2.4.2)
47
+
48
+ PLATFORMS
49
+ ruby
50
+ x86_64-darwin-15
51
+ x86_64-darwin-17
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 2.2.20)
55
+ codeclimate-test-reporter (~> 1)
56
+ except_nested!
57
+ rake (~> 13.0)
58
+ rspec (~> 3.0)
59
+ simplecov (~> 0.21)
60
+
61
+ BUNDLED WITH
62
+ 2.2.24
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # Except Nested
2
2
  [![Gem Version](https://badge.fury.io/rb/except_nested.svg)](https://rubygems.org/gems/except_nested)
3
- [![Build Status](https://travis-ci.org/abarrak/except_nested.svg?branch=master)](https://travis-ci.org/abarrak/except_nested)
4
- [![Dependency Status](https://gemnasium.com/badges/github.com/abarrak/except_nested.svg)](https://gemnasium.com/github.com/abarrak/except_nested)
3
+ [![Build Status](https://www.travis-ci.com/abarrak/except_nested.svg?branch=master)](https://www.travis-ci.com/abarrak/except_nested)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/9c4a7dd09de4a3b328da/test_coverage)](https://codeclimate.com/github/abarrak/except_nested/test_coverage)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/9c4a7dd09de4a3b328da/maintainability)](https://codeclimate.com/github/abarrak/except_nested/maintainability)
5
6
 
6
- **except_nested** allows exclusion of given hash keys at varies depth of the hash.
7
+ **except_nested** allows exclusion of given hash keys at various depth of the hash.
7
8
 
8
- It's an extended version of active_support `#except` hash utility
9
+ It's an extended version of active_support `#except` hash utility.
9
10
 
10
11
  ## Installation
11
12
 
@@ -28,10 +29,50 @@ $ gem install except_nested
28
29
  ```
29
30
 
30
31
  ## Usage
31
- TODO ...
32
+ Given the following hash:
33
+
34
+ ```ruby
35
+ h = { name: 'Zohoor', degree: 'Psychology', preferences: { color: 'mauve', drink: 'coffee', pet: 'cat' } }
36
+ ```
37
+
38
+ You can deep except keys:
39
+
40
+ ```ruby
41
+ h.except_nested(:degree, preferences: [:color, :pet])
42
+ => { name: "Zohoor", preferences: { drink: "coffee" } }
43
+
44
+ h.except_nested(preferences: :pet)
45
+ => { name: "Zohoor", degree: "Psychology", preferences: { color: "mauve", drink: "coffee" } }
46
+
47
+ h.except_nested(preferences: [:pet], :name)
48
+ => { degree: "Psychology", preferences: { color: "mauve", drink: "coffee" } }
49
+
50
+ h.except_nested(:degree, preferences: [:color, :pet, :drink])
51
+ => { name: "Zohoor" }
52
+
53
+ # original hash is preserved ..
54
+ h
55
+ => { name: "Zohoor", degree: "Psychology", preferences: { color: "mauve", drink: "coffee", pet: "cat" } }
56
+ ```
57
+
58
+ Or exclude keys in the first level just like normal `#except` does:
59
+
60
+ ```ruby
61
+ h.except_nested(:name)
62
+ => { degree: "Psychology", preferences: { color: "mauve", drink: "coffee", pet: "cat" } }
63
+
64
+ h.except_nested(:name, :degree)
65
+ => { preferences: { color: "mauve", drink: "coffee", pet: "cat" } }
66
+
67
+ h.except_nested(:name, :degree, :preferences)
68
+ => {}
69
+ ```
70
+
71
+ It works for any nested levels. Check [test case](https://github.com/abarrak/except_nested/blob/master/spec/except_nested_spec.rb#L87-L105) for 3-level depth example.
32
72
 
33
73
  ## Documentation
34
- TODO ...
74
+
75
+ [RDoc version](http://www.rubydoc.info/gems/except_nested) at RubyDoc.
35
76
 
36
77
  ## Development
37
78
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.email = ["abdullah@abarrak.com"]
14
14
 
15
15
  spec.summary = "An extended version of active_support #except hash utility."
16
- spec.description = "except_nested allows exclusion of given hash keys at varies depth."
16
+ spec.description = "except_nested allows extraction of given hash values at various depth of the hash."
17
17
  spec.homepage = "https://github.com/abarrak/except_nested"
18
18
  spec.license = "MIT"
19
19
 
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_dependency 'activesupport', '~> 4.2'
28
- spec.add_development_dependency "bundler", "~> 1.15"
29
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_dependency 'activesupport', '~> 6'
28
+ spec.add_development_dependency "bundler", "~> 2.2.20"
29
+ spec.add_development_dependency "rake", "~> 13.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "simplecov", "~> 0.12.0"
32
- spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4.8"
31
+ spec.add_development_dependency "simplecov", "~> 0.21"
32
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1"
33
33
  end
@@ -17,14 +17,14 @@ class Hash
17
17
 
18
18
  # Removes the given nested keys from hash and returns it.
19
19
  # hash = { a: true, b: { x: true, y: false }, c: nil }
20
- # hash.except_nested(b: [:y]) # => { a: true, b: { x: true }, c: nil }
21
- # hash # => { a: true, b: false }
20
+ # hash.except_nested!(b: [:y]) # => { a: true, b: { x: true }, c: nil }
21
+ # hash # => { a: true, b: { x: true }, c: nil }
22
22
  def except_nested!(*nested_keys)
23
23
  nested_keys.each do |key|
24
24
  if key.is_a?(Hash)
25
25
  key.each do |sub_key, sub_value|
26
26
  if sub_value.is_a?(Array)
27
- self[sub_key].delete_if { |k, v| sub_value.include?(k) }
27
+ self[sub_key].delete_if { |k, _| sub_value.include?(k) }
28
28
  delete(sub_key) if self[sub_key].empty?
29
29
  elsif sub_value.is_a?(Hash)
30
30
  self[sub_key].except_nested!(sub_value)
@@ -33,7 +33,7 @@ class Hash
33
33
  end
34
34
  end
35
35
  elsif key.is_a?(Array)
36
- delete_if { |k, v| k == key.first }
36
+ delete_if { |k, _| k == key.first }
37
37
  else
38
38
  delete(key)
39
39
  end
@@ -1,3 +1,3 @@
1
1
  module ExceptNested
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: except_nested
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdullah Barrak
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.15'
33
+ version: 2.2.20
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.15'
40
+ version: 2.2.20
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,29 +72,30 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.12.0
75
+ version: '0.21'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.12.0
82
+ version: '0.21'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.4.8
89
+ version: '1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.4.8
97
- description: except_nested allows exclusion of given hash keys at varies depth.
96
+ version: '1'
97
+ description: except_nested allows extraction of given hash values at various depth
98
+ of the hash.
98
99
  email:
99
100
  - abdullah@abarrak.com
100
101
  executables: []
@@ -107,6 +108,7 @@ files:
107
108
  - ".ruby-version"
108
109
  - ".travis.yml"
109
110
  - Gemfile
111
+ - Gemfile.lock
110
112
  - LICENSE.txt
111
113
  - README.md
112
114
  - Rakefile
@@ -120,7 +122,7 @@ homepage: https://github.com/abarrak/except_nested
120
122
  licenses:
121
123
  - MIT
122
124
  metadata: {}
123
- post_install_message:
125
+ post_install_message:
124
126
  rdoc_options: []
125
127
  require_paths:
126
128
  - lib
@@ -135,9 +137,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  - !ruby/object:Gem::Version
136
138
  version: '0'
137
139
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.6.12
140
- signing_key:
140
+ rubyforge_project:
141
+ rubygems_version: 2.7.6.2
142
+ signing_key:
141
143
  specification_version: 4
142
144
  summary: 'An extended version of active_support #except hash utility.'
143
145
  test_files: []