except_nested 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/except_nested.gemspec +33 -0
- data/lib/except_nested/core_ext/hash/except_nested.rb +43 -0
- data/lib/except_nested/version.rb +3 -0
- data/lib/except_nested.rb +5 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce8d61447e18525bc6d98dae31ffe737eb4d8882
|
4
|
+
data.tar.gz: fbceed209c89579f5ab75a507920a947b796018d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd6da6fecdf470ff9eb8bb0e28346b5cae692121d6e594cbb60a8c3411fa9537c4ec36bd62f2f099142f6052a8f161c6db281b88d29669999079ba29c12d320b
|
7
|
+
data.tar.gz: 7033a86553ebc7698351cab2bd198b67c8fe47dddb632545ecf24cea0680bb58c61f38025a4d86e5883e99966a7b50cbf642c948a13cbe170e9b19f851daab1a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
except_nested
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Abdullah Barrak
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Except Nested
|
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)
|
5
|
+
|
6
|
+
**except_nested** allows exclusion of given hash keys at varies depth of the hash.
|
7
|
+
|
8
|
+
It's an extended version of active_support `#except` hash utility
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'except_nested'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
```shell
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
$ gem install except_nested
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
TODO ...
|
32
|
+
|
33
|
+
## Documentation
|
34
|
+
TODO ...
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
39
|
+
|
40
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
43
|
+
|
44
|
+
To release a new version, update the version number in `version.rb`, and then 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).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/abarrak/except_nested).
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "except_nested"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require "date"
|
6
|
+
require "except_nested/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "except_nested"
|
10
|
+
spec.version = ExceptNested::VERSION
|
11
|
+
spec.date = Date.today.to_s
|
12
|
+
spec.authors = ["Abdullah Barrak"]
|
13
|
+
spec.email = ["abdullah@abarrak.com"]
|
14
|
+
|
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."
|
17
|
+
spec.homepage = "https://github.com/abarrak/except_nested"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency 'activesupport', '~> 4.2'
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
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"
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "active_support/core_ext/object/deep_dup"
|
2
|
+
require "active_support/core_ext/array/wrap"
|
3
|
+
|
4
|
+
class Hash
|
5
|
+
# Returns a hash that includes everything except given nested keys.
|
6
|
+
# hash = { a: true, b: { x: true, y: false }, c: nil }
|
7
|
+
# hash.except_nested(:b, :c) # => { a: true }
|
8
|
+
# hash.except_nested(:a, b: [:x]) # => { b: { y: false }, c: nil }
|
9
|
+
# hash.except_nested(:a, b: [:x, :y]) # => { c: nil }
|
10
|
+
# hash # => { a: true, b: { x: true, y: false }, c: nil }
|
11
|
+
#
|
12
|
+
# It's useful for limiting a set of parameters to everything but a few known toggles at any depth.
|
13
|
+
# @person.update(params[:person].except_nested(:admin, settings: [:secrect_key]))
|
14
|
+
def except_nested(*nested_keys)
|
15
|
+
deep_dup.except_nested!(*nested_keys)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Removes the given nested keys from hash and returns it.
|
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 }
|
22
|
+
def except_nested!(*nested_keys)
|
23
|
+
nested_keys.each do |key|
|
24
|
+
if key.is_a?(Hash)
|
25
|
+
key.each do |sub_key, sub_value|
|
26
|
+
if sub_value.is_a?(Array)
|
27
|
+
self[sub_key].delete_if { |k, v| sub_value.include?(k) }
|
28
|
+
delete(sub_key) if self[sub_key].empty?
|
29
|
+
elsif sub_value.is_a?(Hash)
|
30
|
+
self[sub_key].except_nested!(sub_value)
|
31
|
+
else
|
32
|
+
self[sub_key].except_nested!(Array.wrap(sub_value))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
elsif key.is_a?(Array)
|
36
|
+
delete_if { |k, v| k == key.first }
|
37
|
+
else
|
38
|
+
delete(key)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: except_nested
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abdullah Barrak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
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.12.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.12.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.8
|
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.8
|
97
|
+
description: except_nested allows exclusion of given hash keys at varies depth.
|
98
|
+
email:
|
99
|
+
- abdullah@abarrak.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".ruby-gemset"
|
107
|
+
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- except_nested.gemspec
|
116
|
+
- lib/except_nested.rb
|
117
|
+
- lib/except_nested/core_ext/hash/except_nested.rb
|
118
|
+
- lib/except_nested/version.rb
|
119
|
+
homepage: https://github.com/abarrak/except_nested
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.6.12
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: 'An extended version of active_support #except hash utility.'
|
143
|
+
test_files: []
|