metanorma-utils 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +51 -0
- data/.rubocop.yml +6 -0
- data/Rakefile +0 -2
- data/lib/utils/hash_transform_keys.rb +51 -0
- data/lib/utils/version.rb +1 -1
- data/spec/hash_transform_keys_spec.rb +52 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3526191e2ba7aa687c2627431bf6396b517524f70a69a83a195cecc6b950f7
|
4
|
+
data.tar.gz: 55aaaaede4a6ebf0332df54fd5bbb6d8c064a71d2154f2c8ee16c71e12826ab7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711e4fd01162a9e169aaa1ef25bbc43f0159cf35141d548765d73d117e102660864493ef9a0cc62b5744dde661e0dc36a2c6dceb94d0a6b0ba0c1a03228c80f7
|
7
|
+
data.tar.gz: 5d102770c31df5de6732a6553b884e8c05fb56bcdb062bf1bd621c8c1fc9220d7f0d259c46d58a6e45f7f3cfd24da11cc2c43da1725a35d3581ebef6ac2af1a6
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: rake
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
continue-on-error: ${{ matrix.experimental }}
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
|
+
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
|
+
experimental: [ false ]
|
22
|
+
include:
|
23
|
+
- ruby: '3.0'
|
24
|
+
os: 'ubuntu-latest'
|
25
|
+
experimental: true
|
26
|
+
- ruby: '3.0'
|
27
|
+
os: 'windows-latest'
|
28
|
+
experimental: true
|
29
|
+
- ruby: '3.0'
|
30
|
+
os: 'macos-latest'
|
31
|
+
experimental: true
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@master
|
34
|
+
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
39
|
+
|
40
|
+
- run: bundle exec rake
|
41
|
+
|
42
|
+
tests-passed:
|
43
|
+
needs: rake
|
44
|
+
runs-on: ubuntu-latest
|
45
|
+
steps:
|
46
|
+
- uses: peter-evans/repository-dispatch@v1
|
47
|
+
with:
|
48
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
49
|
+
repository: ${{ github.repository }}
|
50
|
+
event-type: notify
|
51
|
+
client-payload: '{"ref": "${{ github.ref }}"}'
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# This project follows the Ribose OSS style guide.
|
2
|
+
# https://github.com/riboseinc/oss-guides
|
3
|
+
# All project-specific additions and overrides should be specified in this file.
|
4
|
+
|
5
|
+
inherit_from:
|
6
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
data/Rakefile
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Array
|
2
|
+
def stringify_all_keys
|
3
|
+
map do |v|
|
4
|
+
case v
|
5
|
+
when Hash, Array
|
6
|
+
v.stringify_all_keys
|
7
|
+
else
|
8
|
+
v
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def symbolize_all_keys
|
14
|
+
map do |v|
|
15
|
+
case v
|
16
|
+
when Hash, Array
|
17
|
+
v.symbolize_all_keys
|
18
|
+
else
|
19
|
+
v
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Hash
|
26
|
+
def stringify_all_keys
|
27
|
+
result = {}
|
28
|
+
each do |k, v|
|
29
|
+
result[k.to_s] = case v
|
30
|
+
when Hash, Array
|
31
|
+
v.stringify_all_keys
|
32
|
+
else
|
33
|
+
v
|
34
|
+
end
|
35
|
+
end
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def symbolize_all_keys
|
40
|
+
result = {}
|
41
|
+
each do |k, v|
|
42
|
+
result[k.to_sym] = case v
|
43
|
+
when Hash, Array
|
44
|
+
v.symbolize_all_keys
|
45
|
+
else
|
46
|
+
v
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
end
|
data/lib/utils/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "utils/hash_transform_keys"
|
3
|
+
|
4
|
+
RSpec.describe Metanorma::Utils do
|
5
|
+
it "deep stringify hash but skip values" do
|
6
|
+
result = {
|
7
|
+
test0: :test0,
|
8
|
+
test1: false,
|
9
|
+
test2: {
|
10
|
+
test20: :test20,
|
11
|
+
},
|
12
|
+
test3: %i(test31 test32 test33),
|
13
|
+
test4: [
|
14
|
+
{
|
15
|
+
test41: :test41,
|
16
|
+
},
|
17
|
+
],
|
18
|
+
}.stringify_all_keys
|
19
|
+
|
20
|
+
expect(result).to include("test0", "test1", "test2", "test3", "test4")
|
21
|
+
expect(result["test0"]).to eq(:test0)
|
22
|
+
expect(result["test2"]).to include("test20")
|
23
|
+
expect(result["test2"]["test20"]).to eq(:test20)
|
24
|
+
expect(result["test3"]).to include(:test31, :test32, :test33)
|
25
|
+
expect(result["test4"][0]).to include("test41")
|
26
|
+
expect(result["test4"][0]["test41"]).to eq(:test41)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "deep symbolize hash but skip values" do
|
30
|
+
result = {
|
31
|
+
test0: "test0",
|
32
|
+
test1: false,
|
33
|
+
test2: {
|
34
|
+
test20: "test20",
|
35
|
+
},
|
36
|
+
test3: %w(test31 test32 test33),
|
37
|
+
test4: [
|
38
|
+
{
|
39
|
+
test41: "test41",
|
40
|
+
},
|
41
|
+
],
|
42
|
+
}.stringify_all_keys.symbolize_all_keys
|
43
|
+
|
44
|
+
expect(result).to include(:test0, :test1, :test2, :test3, :test4)
|
45
|
+
expect(result[:test0]).to eq("test0")
|
46
|
+
expect(result[:test2]).to include(:test20)
|
47
|
+
expect(result[:test2][:test20]).to eq("test20")
|
48
|
+
expect(result[:test3]).to include("test31", "test32", "test33")
|
49
|
+
expect(result[:test4][0]).to include(:test41)
|
50
|
+
expect(result[:test4][0][:test41]).to eq("test41")
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sterile
|
@@ -243,17 +243,21 @@ executables: []
|
|
243
243
|
extensions: []
|
244
244
|
extra_rdoc_files: []
|
245
245
|
files:
|
246
|
+
- ".github/workflows/rake.yml"
|
247
|
+
- ".rubocop.yml"
|
246
248
|
- Gemfile
|
247
249
|
- LICENSE
|
248
250
|
- README.adoc
|
249
251
|
- Rakefile
|
250
252
|
- bin/rspec
|
251
253
|
- lib/metanorma-utils.rb
|
254
|
+
- lib/utils/hash_transform_keys.rb
|
252
255
|
- lib/utils/log.rb
|
253
256
|
- lib/utils/main.rb
|
254
257
|
- lib/utils/version.rb
|
255
258
|
- metanorma-utils.gemspec
|
256
259
|
- spec/fixtures/action_schemaexpg1.svg
|
260
|
+
- spec/hash_transform_keys_spec.rb
|
257
261
|
- spec/spec_helper.rb
|
258
262
|
- spec/utils_spec.rb
|
259
263
|
homepage: https://github.com/metanorma/metanorma-utils
|