epic_hash_cleaner 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 +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/epic_hash_cleaner.gemspec +34 -0
- data/lib/epic_hash_cleaner.rb +30 -0
- data/lib/epic_hash_cleaner/version.rb +3 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1fa7d252636615ba16dad4978c74d31b9a26205
|
4
|
+
data.tar.gz: f9427b1bf1cf1e4e166338a8993ddfa367d29849
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cd00cd2b9eac4da34fcfd6570b6c30a7cd2a3b14c6f8b5aa9f9ecfddf852a28dafdbf44f912f54786405b6e7adfa1878fbde72fcd74a0fa05eef741002f8b20
|
7
|
+
data.tar.gz: 123c0efd9603dbc44ce41a8b0f2b5e6d134ea505f541065a2fffbbc0016a2dcd7c6f05eff58ad5b470dd9dab739dd7edcf9bd0a0ba4615f36cbceadc7a05ffe5
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# See all options in these files:
|
2
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
3
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
|
4
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/disabled.yml
|
5
|
+
|
6
|
+
# run bundle exec rubocop -D to see what cop is reporting
|
7
|
+
|
8
|
+
# If you want to skip the check for line length in a specific case do:
|
9
|
+
# rubocop:disable LineLength
|
10
|
+
# superlong-line-with-unavoidable-excesive-length
|
11
|
+
# rubocop:enable LineLength
|
12
|
+
|
13
|
+
AllCops:
|
14
|
+
TargetRubyVersion: 2.3
|
15
|
+
Exclude:
|
16
|
+
- bin/*
|
17
|
+
- Rakefile
|
18
|
+
|
19
|
+
Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Exclude:
|
24
|
+
- test/**/*
|
25
|
+
- ./*.gemspec
|
26
|
+
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 120
|
29
|
+
Exclude:
|
30
|
+
- test/**/*
|
31
|
+
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Exclude:
|
34
|
+
- test/**/*
|
35
|
+
|
36
|
+
Style/FrozenStringLiteralComment:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Although casecmp is more performant, downcase is more readable
|
40
|
+
# 'Foo'.downcase.eql?('foo') vs 'Foo'.casecmp('foo').zero?
|
41
|
+
Performance/Casecmp:
|
42
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 i22 Digitalagentur GmbH
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# EpicHashCleaner
|
2
|
+
[](https://travis-ci.org/i22-digitalagentur/epic-hash-cleaner)
|
3
|
+
|
4
|
+
Removes recursively nil and empty elements from a hash
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
# Examples
|
8
|
+
|
9
|
+
EpicHashCleaner.clean { a: nil, b: '', c: [], d: {} }
|
10
|
+
# => {}
|
11
|
+
|
12
|
+
EpicHashCleaner.clean { a: false, b: ' ' }
|
13
|
+
# => { a: false, b: ' ' }
|
14
|
+
|
15
|
+
EpicHashCleaner.clean { a: [nil], b: [nil, '', [{}], { a: [''] }] }
|
16
|
+
# => {}
|
17
|
+
|
18
|
+
EpicHashCleaner.clean { a: { b: { c: [{ d: ['', 1], e: nil }] } } }
|
19
|
+
# => { a: { b: { c: [{ d: [1] }] } } }
|
20
|
+
```
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'epic_hash_cleaner'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install epic_hash_cleaner
|
37
|
+
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/i22-digitalagentur/epic-hash-cleaner
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
47
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "epic_hash_cleaner"
|
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,34 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'epic_hash_cleaner/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'epic_hash_cleaner'
|
7
|
+
spec.version = EpicHashCleaner::VERSION
|
8
|
+
spec.authors = ['fsainz']
|
9
|
+
spec.email = ['fernando.sainz@i22.de']
|
10
|
+
|
11
|
+
spec.summary = 'Removes recursively nil and empty elements from a hash'
|
12
|
+
spec.homepage = 'https://github.com/i22-digitalagentur/epic-hash-cleaner'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
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_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'm'
|
29
|
+
spec.add_development_dependency 'minitest'
|
30
|
+
spec.add_development_dependency 'pry'
|
31
|
+
spec.add_development_dependency 'rake'
|
32
|
+
spec.add_development_dependency 'rubocop', '0.52.1'
|
33
|
+
spec.add_development_dependency 'simplecov'
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Dir[File.join(__dir__, 'epic_hash_cleaner/*.rb')].each { |path| require path }
|
2
|
+
|
3
|
+
module EpicHashCleaner
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def clean(hash)
|
7
|
+
clean_hash(hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
def clean_hash(hash)
|
11
|
+
hash.delete_if { |_, v| clean_value(v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def clean_array(array)
|
15
|
+
array.delete_if { |v| clean_value(v) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def clean_value(value)
|
19
|
+
clean_hash(value) if value.is_a?(Hash)
|
20
|
+
clean_array(value) if value.is_a?(Array)
|
21
|
+
blank?(value) if value != false
|
22
|
+
end
|
23
|
+
|
24
|
+
# based on File activesupport/lib/active_support/core_ext/object/blank.rb
|
25
|
+
# rubocop:disable Style/DoubleNegation
|
26
|
+
def blank?(value)
|
27
|
+
value.respond_to?(:empty?) ? !!value.empty? : !value
|
28
|
+
end
|
29
|
+
# rubocop:enable Style/DoubleNegation
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epic_hash_cleaner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fsainz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: m
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
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
|
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: '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'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.52.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.52.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- fernando.sainz@i22.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- epic_hash_cleaner.gemspec
|
128
|
+
- lib/epic_hash_cleaner.rb
|
129
|
+
- lib/epic_hash_cleaner/version.rb
|
130
|
+
homepage: https://github.com/i22-digitalagentur/epic-hash-cleaner
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
allowed_push_host: https://rubygems.org
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.5.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Removes recursively nil and empty elements from a hash
|
155
|
+
test_files: []
|