serialized-hashie 1.0.1 → 1.1.4
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 +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/package.yml +4 -1
- data/.gitignore +6 -0
- data/Appraisals +9 -0
- data/MIT-LICENSE +20 -0
- data/lib/serialized_hashie.rb +4 -0
- data/lib/serialized_hashie/hash.rb +49 -12
- data/lib/serialized_hashie/version.rb +6 -1
- data/serialized-hashie.gemspec +5 -2
- metadata +23 -7
- data/Gemfile.lock +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 300103bd38c44cb166420b1acc239e8ef20bc0f1c7d9f4bf12e929834a44666c
|
4
|
+
data.tar.gz: daaf36066c71f252d3d33f38f3ac6bcab310a1491b18badad7f985d9fbad1a3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb43c83b54941b0b81628aa37441741a931205b73ce8c0f52e5d0ffc260b0fc1e845795748c0745a8faf108a2ad13413ed696f88cb52ab1cea9b5da32ed7f80
|
7
|
+
data.tar.gz: bfc8aa01bfdbe685901ab35952ad5ba437570b4bdc6d50b1fabe3780b2d133166398d8024888aed392787096271f7f41f6a2f64afa2f9a9d9620b80eb634babc
|
data/.github/workflows/ci.yml
CHANGED
@@ -16,6 +16,6 @@ jobs:
|
|
16
16
|
ruby-version: ${{ matrix.ruby_version }}
|
17
17
|
- uses: actions/checkout@v2
|
18
18
|
- name: Install dependencies
|
19
|
-
run: bundle install
|
19
|
+
run: bundle install && bundle exec appraisal install
|
20
20
|
- name: Run tests
|
21
|
-
run: bundle exec rspec
|
21
|
+
run: bundle exec appraisal rspec
|
@@ -15,7 +15,10 @@ jobs:
|
|
15
15
|
- name: Set up Ruby 2.6
|
16
16
|
uses: actions/setup-ruby@v1
|
17
17
|
with:
|
18
|
-
version: 2.6.x
|
18
|
+
ruby-version: 2.6.x
|
19
|
+
|
20
|
+
- name: Export version from tag name
|
21
|
+
run: echo "${GITHUB_REF/refs\/tags\//}" > VERSION
|
19
22
|
|
20
23
|
- name: Build Gem
|
21
24
|
run: gem build *.gemspec
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Krystal Hosting Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/serialized_hashie.rb
CHANGED
@@ -10,22 +10,13 @@ module SerializedHashie
|
|
10
10
|
class << self
|
11
11
|
|
12
12
|
def dump(obj)
|
13
|
-
|
14
|
-
|
15
|
-
if value.is_a?(Array)
|
16
|
-
obj[key] = value.reject { |v| blank?(v) }
|
17
|
-
end
|
18
|
-
|
19
|
-
obj[key] = SerializedHashie.dump_extensions.run(obj[key])
|
20
|
-
end
|
21
|
-
obj.to_h.to_json
|
13
|
+
hash = dump_hash(obj)
|
14
|
+
hash.to_json
|
22
15
|
end
|
23
16
|
|
24
17
|
def load(raw_hash)
|
25
18
|
hash = JSON.parse(presence(raw_hash) || '{}')
|
26
|
-
hash
|
27
|
-
hash[key] = SerializedHashie.load_extensions.run(value)
|
28
|
-
end
|
19
|
+
hash = load_hash(hash)
|
29
20
|
new(hash)
|
30
21
|
end
|
31
22
|
|
@@ -42,6 +33,52 @@ module SerializedHashie
|
|
42
33
|
blank?(value) ? nil : value
|
43
34
|
end
|
44
35
|
|
36
|
+
def dump_hash(hash)
|
37
|
+
hash = hash.transform_values do |value|
|
38
|
+
dump_value(value)
|
39
|
+
end
|
40
|
+
hash.reject { |_, v| blank?(v) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def dump_value(value)
|
44
|
+
if blank?(value)
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
|
48
|
+
if value.is_a?(::Hash)
|
49
|
+
return dump_hash(value)
|
50
|
+
end
|
51
|
+
|
52
|
+
if value.is_a?(::Array)
|
53
|
+
return value.map { |v| dump_value(v) }.compact
|
54
|
+
end
|
55
|
+
|
56
|
+
SerializedHashie.dump_extensions.run(value)
|
57
|
+
end
|
58
|
+
|
59
|
+
def load_hash(hash)
|
60
|
+
hash.transform_values do |value|
|
61
|
+
load_value(value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_value(value)
|
66
|
+
if value.is_a?(::Hash)
|
67
|
+
hash = SerializedHashie.load_hash_extensions.run(value)
|
68
|
+
|
69
|
+
# If the result is still a hash, we'll return that here
|
70
|
+
return load_hash(hash) if hash.is_a?(::Hash)
|
71
|
+
|
72
|
+
# If the result is not a hash, we'll just return whatever
|
73
|
+
# was returned as a normal value.
|
74
|
+
return load_value(hash)
|
75
|
+
end
|
76
|
+
|
77
|
+
return value.map { |v| load_value(v) } if value.is_a?(Array)
|
78
|
+
|
79
|
+
SerializedHashie.load_extensions.run(value)
|
80
|
+
end
|
81
|
+
|
45
82
|
end
|
46
83
|
|
47
84
|
end
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module SerializedHashie
|
4
4
|
|
5
|
-
|
5
|
+
VERSION_FILE_ROOT = File.expand_path('../../VERSION', __dir__)
|
6
|
+
if File.file?(VERSION_FILE_ROOT)
|
7
|
+
VERSION = File.read(VERSION_FILE_ROOT).strip.delete_prefix('v')
|
8
|
+
else
|
9
|
+
VERSION = '0.0.0.dev'
|
10
|
+
end
|
6
11
|
|
7
12
|
end
|
data/serialized-hashie.gemspec
CHANGED
@@ -7,10 +7,11 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = SerializedHashie::VERSION
|
8
8
|
spec.authors = ['Adam Cooke']
|
9
9
|
spec.email = ['adam@krystal.uk']
|
10
|
-
|
11
10
|
spec.summary = 'Helpers to serialize data into ActiveRecord models as JSON and returning a Hashie::Mash'
|
12
11
|
spec.description = spec.summary
|
13
12
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
13
|
+
spec.licenses = ['MIT']
|
14
|
+
spec.homepage = 'https://github.com/krystal/serialized-hashie'
|
14
15
|
|
15
16
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
16
17
|
`git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)\//) }
|
@@ -19,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ['lib']
|
21
22
|
|
23
|
+
spec.add_development_dependency 'appraisal', '~> 2.3'
|
24
|
+
|
22
25
|
spec.add_runtime_dependency 'hashie', '>= 4.0', '< 5.0'
|
23
|
-
spec.add_runtime_dependency 'json', '>=
|
26
|
+
spec.add_runtime_dependency 'json', '>= 1.8', '< 3.0'
|
24
27
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialized-hashie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: hashie
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -36,7 +50,7 @@ dependencies:
|
|
36
50
|
requirements:
|
37
51
|
- - ">="
|
38
52
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
53
|
+
version: '1.8'
|
40
54
|
- - "<"
|
41
55
|
- !ruby/object:Gem::Version
|
42
56
|
version: '3.0'
|
@@ -46,7 +60,7 @@ dependencies:
|
|
46
60
|
requirements:
|
47
61
|
- - ">="
|
48
62
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
63
|
+
version: '1.8'
|
50
64
|
- - "<"
|
51
65
|
- !ruby/object:Gem::Version
|
52
66
|
version: '3.0'
|
@@ -62,8 +76,9 @@ files:
|
|
62
76
|
- ".github/workflows/package.yml"
|
63
77
|
- ".gitignore"
|
64
78
|
- ".rubocop.yml"
|
79
|
+
- Appraisals
|
65
80
|
- Gemfile
|
66
|
-
-
|
81
|
+
- MIT-LICENSE
|
67
82
|
- README.md
|
68
83
|
- bin/console
|
69
84
|
- bin/setup
|
@@ -72,8 +87,9 @@ files:
|
|
72
87
|
- lib/serialized_hashie/hash.rb
|
73
88
|
- lib/serialized_hashie/version.rb
|
74
89
|
- serialized-hashie.gemspec
|
75
|
-
homepage:
|
76
|
-
licenses:
|
90
|
+
homepage: https://github.com/krystal/serialized-hashie
|
91
|
+
licenses:
|
92
|
+
- MIT
|
77
93
|
metadata: {}
|
78
94
|
post_install_message:
|
79
95
|
rdoc_options: []
|
data/Gemfile.lock
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
serialized-hashie (1.0.1)
|
5
|
-
hashie (>= 4.0, < 5.0)
|
6
|
-
json (>= 2.0, < 3.0)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
ast (2.4.0)
|
12
|
-
diff-lcs (1.3)
|
13
|
-
hashie (4.1.0)
|
14
|
-
json (2.1.0)
|
15
|
-
parallel (1.19.1)
|
16
|
-
parser (2.7.1.2)
|
17
|
-
ast (~> 2.4.0)
|
18
|
-
rainbow (3.0.0)
|
19
|
-
rake (12.3.3)
|
20
|
-
rexml (3.2.4)
|
21
|
-
rspec (3.9.0)
|
22
|
-
rspec-core (~> 3.9.0)
|
23
|
-
rspec-expectations (~> 3.9.0)
|
24
|
-
rspec-mocks (~> 3.9.0)
|
25
|
-
rspec-core (3.9.2)
|
26
|
-
rspec-support (~> 3.9.3)
|
27
|
-
rspec-expectations (3.9.2)
|
28
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
-
rspec-support (~> 3.9.0)
|
30
|
-
rspec-mocks (3.9.1)
|
31
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.9.0)
|
33
|
-
rspec-support (3.9.3)
|
34
|
-
rubocop (0.83.0)
|
35
|
-
parallel (~> 1.10)
|
36
|
-
parser (>= 2.7.0.1)
|
37
|
-
rainbow (>= 2.2.2, < 4.0)
|
38
|
-
rexml
|
39
|
-
ruby-progressbar (~> 1.7)
|
40
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
41
|
-
ruby-progressbar (1.10.1)
|
42
|
-
unicode-display_width (1.7.0)
|
43
|
-
|
44
|
-
PLATFORMS
|
45
|
-
ruby
|
46
|
-
|
47
|
-
DEPENDENCIES
|
48
|
-
rake (~> 12.0)
|
49
|
-
rspec (~> 3.0)
|
50
|
-
rubocop
|
51
|
-
serialized-hashie!
|
52
|
-
|
53
|
-
BUNDLED WITH
|
54
|
-
2.1.4
|