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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8316c849024c1d50c4187236c02c021c6ee1dae96d977e4634a4092f6143545
4
- data.tar.gz: caf0a5aca6847cb91a43334f61eda55dd371ef205e175e88caf85433b47c7799
3
+ metadata.gz: 1f3526191e2ba7aa687c2627431bf6396b517524f70a69a83a195cecc6b950f7
4
+ data.tar.gz: 55aaaaede4a6ebf0332df54fd5bbb6d8c064a71d2154f2c8ee16c71e12826ab7
5
5
  SHA512:
6
- metadata.gz: 5e87d1d6028e5ecd8f4518f8d02c43ca16f8aca81dc3a74b814631372e52b32a2df72313f5eb2304632faaf1248f65653cb4296366183e9e54b2c327f8abf17a
7
- data.tar.gz: 98cc1f5cdaf5206072b7726fdd9771382aa754a03b7e1310113ea1ea6f80f082bb8596b700d620406ee24a6fc345de58d646291174fd0ba79549259393169547
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
@@ -1,8 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require 'isodoc/gem_tasks'
4
3
 
5
- IsoDoc::GemTasks.install
6
4
  RSpec::Core::RakeTask.new(:spec)
7
5
 
8
6
  task default: :spec
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.0.3".freeze
3
+ VERSION = "1.0.4".freeze
4
4
  end
5
5
  end
@@ -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.3
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-01 00:00:00.000000000 Z
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