darthjee-core_ext 2.0.0 → 3.0.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 +5 -5
- data/.circleci/config.yml +59 -11
- data/.rubocop.yml +18 -1
- data/.rubocop_todo.yml +15 -8
- data/Dockerfile +19 -3
- data/Gemfile +13 -0
- data/Makefile +7 -0
- data/README.md +5 -1
- data/config/check_specs.yml +20 -0
- data/core_ext.gemspec +3 -13
- data/docker-compose.yml +9 -0
- data/lib/darthjee/core_ext/array/hash_builder.rb +2 -1
- data/lib/darthjee/core_ext/array.rb +5 -2
- data/lib/darthjee/core_ext/class.rb +1 -0
- data/lib/darthjee/core_ext/enumerable.rb +6 -5
- data/lib/darthjee/core_ext/hash/cameliazable.rb +13 -13
- data/lib/darthjee/core_ext/hash/chain_fetcher.rb +1 -0
- data/lib/darthjee/core_ext/hash/changeable.rb +4 -4
- data/lib/darthjee/core_ext/hash/deep_hash_constructor.rb +3 -2
- data/lib/darthjee/core_ext/hash/key_changeable.rb +15 -15
- data/lib/darthjee/core_ext/hash/key_changer.rb +12 -11
- data/lib/darthjee/core_ext/hash/keys_sorter.rb +1 -0
- data/lib/darthjee/core_ext/hash/transformable.rb +1 -1
- data/lib/darthjee/core_ext/hash.rb +2 -2
- data/lib/darthjee/core_ext/numeric.rb +3 -2
- data/lib/darthjee/core_ext/object.rb +0 -2
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/spec/integration/readme/class_spec.rb +3 -3
- data/spec/integration/readme/hash_spec.rb +10 -1
- data/spec/integration/yard/darthjee/core_ext/array_spec.rb +1 -1
- data/spec/integration/yard/darthjee/core_ext/class/default_value_spec.rb +10 -8
- data/spec/integration/yard/darthjee/core_ext/hash/deep_hash_constructor_spec.rb +10 -10
- data/spec/integration/yard/darthjee/core_ext/hash/squasher_spec.rb +3 -3
- data/spec/integration/yard/darthjee/core_ext/hash/transformable_spec.rb +3 -3
- data/spec/integration/yard/darthjee/core_ext/hash/transposeable_spec.rb +1 -1
- data/spec/integration/yard/darthjee/core_ext/hash/value_changer_spec.rb +1 -1
- data/spec/lib/array_spec.rb +2 -1
- data/spec/lib/darthjee/core_ext/hash/value_changer_spec.rb +1 -1
- data/spec/lib/hash_spec.rb +1 -7
- data/spec/lib/symbol_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -2
- data/spec/support/models/client.rb +2 -1
- data/spec/support/models/dummy_iterator.rb +4 -4
- data/spec/support/models/hash/value_changer/dummy.rb +1 -0
- data/spec/support/shared_examples/array/array_random.rb +2 -3
- data/spec/support/shared_examples/hash/chain_hash_keys_changer.rb +1 -1
- data/spec/support/shared_examples/hash/hash_keys_changer.rb +3 -3
- data/spec/support/shared_examples/hash/map_to_hash.rb +1 -1
- data/spec/support/shared_examples/hash/remap.rb +4 -4
- data/spec/support/shared_examples/hash/value_changer.rb +2 -2
- metadata +12 -222
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 488d3a9ef14a0b2369f3d281bc0ab6433eeb29ef9696cda0bb77886b6a0528ca
|
4
|
+
data.tar.gz: 78a996784bc1dda49f0a2349ec25d8b131576967e4262f3523ded5a25ca52e74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76d650ce4908f61c4e9fd88cb8ae6e1ba8712a05e4d5ce07eea7a048f91bf78e1926cbafa1695eaca167a57645832977546e53a8eac8309424fdbf4e077174f
|
7
|
+
data.tar.gz: 523348bc447c0299531540dd1308b7ff202d2e7a2da59c84b292a85c4883ee1b20cd16637b6cd51ec51b0241180f5917059dc3639c74f8eca98feff854c9dd65
|
data/.circleci/config.yml
CHANGED
@@ -1,31 +1,79 @@
|
|
1
1
|
version: 2
|
2
|
+
workflows:
|
3
|
+
version: 2
|
4
|
+
test-and-build:
|
5
|
+
jobs:
|
6
|
+
- test:
|
7
|
+
filters:
|
8
|
+
tags:
|
9
|
+
only: /.*/
|
10
|
+
- checks:
|
11
|
+
filters:
|
12
|
+
tags:
|
13
|
+
only: /.*/
|
14
|
+
- build-and-release:
|
15
|
+
requires: [test, checks]
|
16
|
+
filters:
|
17
|
+
tags:
|
18
|
+
only: /\d+\.\d+\.\d+/
|
19
|
+
branches:
|
20
|
+
only:
|
21
|
+
- main
|
2
22
|
jobs:
|
3
|
-
|
23
|
+
test:
|
4
24
|
docker:
|
5
|
-
- image: darthjee/
|
25
|
+
- image: darthjee/circleci_ruby_331:1.0.2
|
26
|
+
environment:
|
27
|
+
PROJECT: core_ext
|
6
28
|
steps:
|
7
29
|
- checkout
|
8
|
-
- run:
|
9
|
-
name: Prepare Coverage Test Report
|
10
|
-
command: cc-test-reporter before-build
|
11
30
|
- run:
|
12
31
|
name: Bundle Install
|
13
32
|
command: bundle install
|
14
33
|
- run:
|
15
34
|
name: RSpec
|
16
|
-
command: bundle exec rspec
|
35
|
+
command: COVERAGE_JSON=true bundle exec rspec
|
36
|
+
checks:
|
37
|
+
docker:
|
38
|
+
- image: darthjee/circleci_ruby_331:1.0.2
|
39
|
+
environment:
|
40
|
+
PROJECT: core_ext
|
41
|
+
steps:
|
42
|
+
- checkout
|
43
|
+
- run:
|
44
|
+
name: Bundle Install
|
45
|
+
command: bundle install
|
17
46
|
- run:
|
18
47
|
name: Rubocop
|
19
48
|
command: rubocop
|
20
|
-
- run:
|
21
|
-
name: Coverage Test Report
|
22
|
-
command: cc-test-reporter after-build --exit-code $?
|
23
49
|
- run:
|
24
50
|
name: Yardstick coverage check
|
25
51
|
command: bundle exec rake verify_measurements
|
26
52
|
- run:
|
27
53
|
name: Check version documentation
|
28
|
-
command:
|
54
|
+
command: PROJECT=darthjee-core_ext check_readme.sh
|
29
55
|
- run:
|
30
56
|
name: Rubycritcs check
|
31
|
-
command:
|
57
|
+
command: rubycritic.sh
|
58
|
+
- run:
|
59
|
+
name: Check unit tests
|
60
|
+
command: check_specs
|
61
|
+
build-and-release:
|
62
|
+
docker:
|
63
|
+
- image: darthjee/circleci_ruby_331:1.0.2
|
64
|
+
environment:
|
65
|
+
PROJECT: core_ext
|
66
|
+
steps:
|
67
|
+
- checkout
|
68
|
+
- run:
|
69
|
+
name: Bundle Install
|
70
|
+
command: bundle install
|
71
|
+
- run:
|
72
|
+
name: Signin
|
73
|
+
command: build_gem.sh signin
|
74
|
+
- run:
|
75
|
+
name: Build Gem
|
76
|
+
command: build_gem.sh build
|
77
|
+
- run:
|
78
|
+
name: Push Gem
|
79
|
+
command: build_gem.sh push
|
data/.rubocop.yml
CHANGED
@@ -2,7 +2,12 @@ require: rubocop-rspec
|
|
2
2
|
inherit_from: .rubocop_todo.yml
|
3
3
|
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion:
|
5
|
+
TargetRubyVersion: 3.3
|
6
|
+
NewCops: enable
|
7
|
+
|
8
|
+
RSpec/MultipleExpectations:
|
9
|
+
Exclude:
|
10
|
+
- 'spec/integration/**/*_spec.rb'
|
6
11
|
|
7
12
|
Naming/PredicateName:
|
8
13
|
Exclude:
|
@@ -18,3 +23,15 @@ RSpec/AlignLeftLetBrace:
|
|
18
23
|
|
19
24
|
RSpec/NestedGroups:
|
20
25
|
Max: 5
|
26
|
+
|
27
|
+
RSpec/IndexedLet:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
RSpec/SpecFilePathFormat:
|
31
|
+
Exclude:
|
32
|
+
- 'spec/integration/**/*_spec.rb'
|
33
|
+
|
34
|
+
Style/HashEachMethods:
|
35
|
+
Exclude:
|
36
|
+
- 'lib/darthjee/core_ext/hash/deep_hash_constructor.rb'
|
37
|
+
- 'lib/darthjee/core_ext/hash/squasher.rb'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2025-02-24 21:33:57 UTC using RuboCop version 1.59.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
|
-
#
|
7
|
+
# versionsuof RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
10
|
-
# Configuration parameters:
|
11
|
-
RSpec/
|
12
|
-
Max:
|
9
|
+
# Offense count: 4
|
10
|
+
# Configuration parameters: AllowSubject.
|
11
|
+
RSpec/MultipleMemoizedHelpers:
|
12
|
+
Max: 6
|
13
13
|
|
14
|
-
# Offense count:
|
14
|
+
# Offense count: 4
|
15
|
+
# Configuration parameters: AllowedConstants.
|
15
16
|
Style/Documentation:
|
16
|
-
|
17
|
+
Exclude:
|
18
|
+
- 'spec/**/*'
|
19
|
+
- 'test/**/*'
|
20
|
+
- 'lib/darthjee.rb'
|
21
|
+
- 'lib/darthjee/core_ext.rb'
|
22
|
+
- 'lib/darthjee/core_ext/hash/transformable.rb'
|
23
|
+
- 'lib/darthjee/core_ext/time.rb'
|
data/Dockerfile
CHANGED
@@ -1,6 +1,22 @@
|
|
1
|
-
FROM darthjee/
|
1
|
+
FROM darthjee/scripts:0.4.3 as scripts
|
2
2
|
|
3
|
-
|
4
|
-
COPY --chown=app ./ /home/app/app/
|
3
|
+
FROM darthjee/ruby_331:1.0.2 as base
|
5
4
|
|
5
|
+
COPY --chown=app:app ./ /home/app/app/
|
6
|
+
|
7
|
+
######################################
|
8
|
+
|
9
|
+
FROM base as builder
|
10
|
+
|
11
|
+
COPY --chown=app:app --from=scripts /home/scripts/builder/bundle_builder.sh /usr/local/sbin/bundle_builder.sh
|
12
|
+
|
13
|
+
ENV HOME_DIR /home/app
|
14
|
+
RUN bundle_builder.sh
|
15
|
+
|
16
|
+
#######################
|
17
|
+
#FINAL IMAGE
|
18
|
+
FROM base
|
19
|
+
|
20
|
+
COPY --chown=app:app --from=builder /home/app/bundle/ /usr/local/bundle/
|
6
21
|
RUN bundle install
|
22
|
+
|
data/Gemfile
CHANGED
@@ -4,3 +4,16 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in credential_builder.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'bundler', '~> 2.6.8'
|
9
|
+
gem 'pry', '0.14.2'
|
10
|
+
gem 'pry-nav', '1.0.0'
|
11
|
+
gem 'rake', '13.2.1'
|
12
|
+
gem 'rspec', '3.13.0'
|
13
|
+
gem 'rubocop', '1.75.5'
|
14
|
+
gem 'rubocop-rspec', '3.6.0'
|
15
|
+
gem 'rubycritic', '4.9.2'
|
16
|
+
gem 'simplecov', '0.22.0'
|
17
|
+
gem 'simplecov_json_formatter', '~> 0.1.3'
|
18
|
+
gem 'yard', '0.9.37'
|
19
|
+
gem 'yardstick', '0.9.9'
|
data/Makefile
ADDED
data/README.md
CHANGED
@@ -10,7 +10,11 @@ Darthjee/CoreExt
|
|
10
10
|
|
11
11
|
Yard Documentation
|
12
12
|
-------------------
|
13
|
-
https://www.rubydoc.info/gems/darthjee-core_ext/
|
13
|
+
[https://www.rubydoc.info/gems/darthjee-core_ext/3.0.0](https://www.rubydoc.info/gems/darthjee-core_ext/3.0.0)
|
14
|
+
|
15
|
+
Current Release: [3.0.0](https://github.com/darthjee/core_ext/tree/3.0.0)
|
16
|
+
|
17
|
+
[Next release](https://github.com/darthjee/core_ext/compare/3.0.0...master)
|
14
18
|
|
15
19
|
# Usage
|
16
20
|
This project adds some new methods to the core ruby classes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
ignore:
|
2
|
+
- lib/darthjee/core_ext/array/hash_builder.rb
|
3
|
+
- lib/darthjee/core_ext/array.rb
|
4
|
+
- lib/darthjee/core_ext/class.rb
|
5
|
+
- lib/darthjee/core_ext/date.rb
|
6
|
+
- lib/darthjee/core_ext/enumerable.rb
|
7
|
+
- lib/darthjee/core_ext/hash/cameliazable.rb
|
8
|
+
- lib/darthjee/core_ext/hash/changeable.rb
|
9
|
+
- lib/darthjee/core_ext/hash/key_changeable.rb
|
10
|
+
- lib/darthjee/core_ext/hash/transformable.rb
|
11
|
+
- lib/darthjee/core_ext/hash/transposeable.rb
|
12
|
+
- lib/darthjee/core_ext/hash.rb
|
13
|
+
- lib/darthjee/core_ext/math.rb
|
14
|
+
- lib/darthjee/core_ext/numeric.rb
|
15
|
+
- lib/darthjee/core_ext/object.rb
|
16
|
+
- lib/darthjee/core_ext/symbol.rb
|
17
|
+
- lib/darthjee/core_ext/time.rb
|
18
|
+
- lib/darthjee/core_ext/version.rb
|
19
|
+
- lib/darthjee/core_ext.rb
|
20
|
+
- lib/darthjee.rb
|
data/core_ext.gemspec
CHANGED
@@ -12,23 +12,13 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = 'Core Extensions'
|
13
13
|
gem.homepage = 'https://github.com/darthjee/core_ext'
|
14
14
|
gem.description = 'Extension of basic classes with usefull methods'
|
15
|
-
gem.required_ruby_version = '>=
|
15
|
+
gem.required_ruby_version = '>= 3.3.1'
|
16
16
|
|
17
17
|
gem.files = `git ls-files -z`.split("\x0")
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
19
|
gem.require_paths = ['lib']
|
21
20
|
|
22
|
-
gem.
|
21
|
+
gem.add_dependency 'activesupport', '~> 7.x'
|
23
22
|
|
24
|
-
gem.
|
25
|
-
gem.add_development_dependency 'pry-nav', '~> 0.2.4'
|
26
|
-
gem.add_development_dependency 'rake', '>= 12.3.1'
|
27
|
-
gem.add_development_dependency 'rspec', '>= 3.8'
|
28
|
-
gem.add_development_dependency 'rubocop', '0.58.1'
|
29
|
-
gem.add_development_dependency 'rubocop-rspec', '1.30.0'
|
30
|
-
gem.add_development_dependency 'rubycritic', '>= 4.0.2'
|
31
|
-
gem.add_development_dependency 'simplecov', '~> 0.16.x'
|
32
|
-
gem.add_development_dependency 'yard', '>= 0.9.18'
|
33
|
-
gem.add_development_dependency 'yardstick', '>= 0.9.9'
|
23
|
+
gem.metadata['rubygems_mfa_required'] = 'true'
|
34
24
|
end
|
data/docker-compose.yml
CHANGED
@@ -21,3 +21,12 @@ services:
|
|
21
21
|
<<: *base
|
22
22
|
depends_on: [base_build]
|
23
23
|
command: /bin/bash -c 'rspec && yard && rake yardstick_measure && rake verify_measurements'
|
24
|
+
|
25
|
+
core_ext_circleci:
|
26
|
+
image: darthjee/circleci_ruby_331:1.0.2
|
27
|
+
container_name: core_ext_circleci
|
28
|
+
command: /bin/bash
|
29
|
+
volumes:
|
30
|
+
- .:/home/circleci/project
|
31
|
+
environment:
|
32
|
+
PROJECT: core_ext
|
@@ -45,7 +45,7 @@ module Darthjee
|
|
45
45
|
def build
|
46
46
|
fixes_sizes
|
47
47
|
|
48
|
-
|
48
|
+
[keys, values].transpose.to_h
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -59,6 +59,7 @@ module Darthjee
|
|
59
59
|
# @return [::Array]
|
60
60
|
def fixes_sizes
|
61
61
|
return unless needs_resizing?
|
62
|
+
|
62
63
|
values.concat ::Array.new(keys.size - values.size)
|
63
64
|
end
|
64
65
|
|
@@ -35,6 +35,7 @@ module Darthjee
|
|
35
35
|
# [].average # returns 0
|
36
36
|
def average
|
37
37
|
return 0 if empty?
|
38
|
+
|
38
39
|
sum * 1.0 / length
|
39
40
|
end
|
40
41
|
|
@@ -60,13 +61,14 @@ module Darthjee
|
|
60
61
|
# output = words.chain_map(:size) do |size|
|
61
62
|
# (size % 2).zero? ? 'even size' : 'odd size'
|
62
63
|
# end # returns ["even size", "even size", "odd size"]
|
63
|
-
def chain_map(*methods, &
|
64
|
+
def chain_map(*methods, &)
|
64
65
|
result = methods.inject(self) do |array, method|
|
65
66
|
array.map(&method)
|
66
67
|
end
|
67
68
|
|
68
69
|
return result unless block_given?
|
69
|
-
|
70
|
+
|
71
|
+
result.map(&)
|
70
72
|
end
|
71
73
|
|
72
74
|
# Maps array chain fetching the keys of the hashes inside
|
@@ -127,6 +129,7 @@ module Darthjee
|
|
127
129
|
# end # returns '1.0 +2.0 -3.0 -4.0 +5.0'
|
128
130
|
def procedural_join(mapper = proc(&:to_s))
|
129
131
|
return '' if empty?
|
132
|
+
|
130
133
|
map = map_to_hash(&mapper)
|
131
134
|
|
132
135
|
map.inject do |(previous, string), (nexte, nexte_string)|
|
@@ -116,8 +116,8 @@ module Enumerable
|
|
116
116
|
# values # returns [3, 1]
|
117
117
|
#
|
118
118
|
# @return [::Array<::Object>]
|
119
|
-
def map_and_select(&
|
120
|
-
map(&
|
119
|
+
def map_and_select(&)
|
120
|
+
map(&).select(&:trueful?)
|
121
121
|
end
|
122
122
|
|
123
123
|
# Maps values and creates a hash
|
@@ -134,9 +134,9 @@ module Enumerable
|
|
134
134
|
#
|
135
135
|
# strings.map_to_hash(&:size) # returns { 'word' => 4, 'big_word' => 8 }
|
136
136
|
def map_to_hash
|
137
|
-
|
137
|
+
to_h do |value|
|
138
138
|
[value, yield(value)]
|
139
|
-
end
|
139
|
+
end
|
140
140
|
end
|
141
141
|
|
142
142
|
private
|
@@ -152,7 +152,8 @@ module Enumerable
|
|
152
152
|
# @return [::TrueClass,::FalseClass]
|
153
153
|
def empty_value?(value)
|
154
154
|
return true unless value.present?
|
155
|
-
return unless value.is_a?(Enumerable)
|
155
|
+
return false unless value.is_a?(Enumerable)
|
156
|
+
|
156
157
|
value.clean!.empty?
|
157
158
|
end
|
158
159
|
end
|
@@ -27,13 +27,13 @@ module Darthjee
|
|
27
27
|
# @example
|
28
28
|
# hash = { first_key: 1, 'second_key' => 2 }
|
29
29
|
# options = { uppercase_first_letter: false }
|
30
|
-
# hash.camelize_keys(options) # returns {
|
30
|
+
# hash.camelize_keys(**options) # returns {
|
31
31
|
# # firstKey: 1,
|
32
32
|
# # 'secondKey' => 2
|
33
33
|
# # }
|
34
34
|
#
|
35
|
-
def camelize_keys(
|
36
|
-
dup.camelize_keys!(
|
35
|
+
def camelize_keys(**)
|
36
|
+
dup.camelize_keys!(**)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Change keys to CamelCase changing the original hash
|
@@ -47,8 +47,8 @@ module Darthjee
|
|
47
47
|
# @example (see #camelize_keys)
|
48
48
|
#
|
49
49
|
# @see #camelize_keys
|
50
|
-
def camelize_keys!(
|
51
|
-
Hash::KeyChanger.new(self).camelize_keys(
|
50
|
+
def camelize_keys!(**)
|
51
|
+
Hash::KeyChanger.new(self).camelize_keys(**)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Camelize all keys in the hash as `key.camelize(:lower)
|
@@ -62,8 +62,8 @@ module Darthjee
|
|
62
62
|
# # 'secondKey' => 2
|
63
63
|
# # }
|
64
64
|
#
|
65
|
-
def lower_camelize_keys(
|
66
|
-
dup.lower_camelize_keys!(
|
65
|
+
def lower_camelize_keys(**)
|
66
|
+
dup.lower_camelize_keys!(**)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Camelize all keys in the hash
|
@@ -71,10 +71,10 @@ module Darthjee
|
|
71
71
|
# @return [::Hash] self after changing the keys
|
72
72
|
#
|
73
73
|
# @example (see #lower_camelize_keys)
|
74
|
-
def lower_camelize_keys!(options
|
74
|
+
def lower_camelize_keys!(**options)
|
75
75
|
options = options.merge(uppercase_first_letter: false)
|
76
76
|
|
77
|
-
camelize_keys!(options)
|
77
|
+
camelize_keys!(**options)
|
78
78
|
end
|
79
79
|
|
80
80
|
# Change all keys to be snakecase
|
@@ -96,8 +96,8 @@ module Darthjee
|
|
96
96
|
# # }
|
97
97
|
#
|
98
98
|
# @return [::Hash]
|
99
|
-
def underscore_keys(
|
100
|
-
dup.underscore_keys!(
|
99
|
+
def underscore_keys(**)
|
100
|
+
dup.underscore_keys!(**)
|
101
101
|
end
|
102
102
|
|
103
103
|
# Change all keys to be snakecase
|
@@ -113,8 +113,8 @@ module Darthjee
|
|
113
113
|
# @example (see #underscore_keys)
|
114
114
|
#
|
115
115
|
# @return [::Hash]
|
116
|
-
def underscore_keys!(
|
117
|
-
Hash::KeyChanger.new(self).underscore_keys(
|
116
|
+
def underscore_keys!(**)
|
117
|
+
Hash::KeyChanger.new(self).underscore_keys(**)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -44,8 +44,8 @@ module Darthjee
|
|
44
44
|
# # a: "1",
|
45
45
|
# # b: "{:c=>1}"
|
46
46
|
# # }
|
47
|
-
def change_values(
|
48
|
-
deep_dup.change_values!(
|
47
|
+
def change_values(**, &)
|
48
|
+
deep_dup.change_values!(**, &)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Changes the values of a hash
|
@@ -79,8 +79,8 @@ module Darthjee
|
|
79
79
|
#
|
80
80
|
# hash # changed to { a: "1", b: "{:c=>2}" }
|
81
81
|
# inner_hash # still { c: 2 }
|
82
|
-
def change_values!(
|
83
|
-
Hash::ValueChanger.new(
|
82
|
+
def change_values!(**, &)
|
83
|
+
Hash::ValueChanger.new(**, &).change(self)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -59,8 +59,8 @@ module Darthjee
|
|
59
59
|
# @example (see DeepHashConstructor)
|
60
60
|
def deep_hash(hash)
|
61
61
|
break_keys(hash).tap do
|
62
|
-
hash.each do |key
|
63
|
-
hash[key] = deep_hash_value(
|
62
|
+
hash.keys.each do |key|
|
63
|
+
hash[key] = deep_hash_value(hash[key])
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -121,6 +121,7 @@ module Darthjee
|
|
121
121
|
def deep_hash_value(object)
|
122
122
|
return array_deep_hash(object) if object.is_a? Array
|
123
123
|
return deep_hash(object) if object.is_a? Hash
|
124
|
+
|
124
125
|
object
|
125
126
|
end
|
126
127
|
|
@@ -51,7 +51,7 @@ module Darthjee
|
|
51
51
|
options = calls.extract_options!
|
52
52
|
|
53
53
|
calls.inject(self) do |h, m|
|
54
|
-
h.change_keys!(options, &m)
|
54
|
+
h.change_keys!(**options, &m)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -80,8 +80,8 @@ module Darthjee
|
|
80
80
|
# (k.to_i + 1).to_s.to_sym
|
81
81
|
# end
|
82
82
|
# result # returns { :'2' => 1, :'3' => { '3' => 2 } }
|
83
|
-
def change_keys(
|
84
|
-
deep_dup.change_keys!(
|
83
|
+
def change_keys(**, &)
|
84
|
+
deep_dup.change_keys!(**, &)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Change all keys modifying and returning the hash
|
@@ -98,8 +98,8 @@ module Darthjee
|
|
98
98
|
# @see Hash::KeyChanger#change_keys
|
99
99
|
#
|
100
100
|
# @example (see #change_keys)
|
101
|
-
def change_keys!(
|
102
|
-
Hash::KeyChanger.new(self).change_keys(
|
101
|
+
def change_keys!(**, &)
|
102
|
+
Hash::KeyChanger.new(self).change_keys(**, &)
|
103
103
|
end
|
104
104
|
|
105
105
|
# prepend a string to all keys
|
@@ -126,8 +126,8 @@ module Darthjee
|
|
126
126
|
# # :foo_a => 1,
|
127
127
|
# # "foo_b"=> 2
|
128
128
|
# # }
|
129
|
-
def prepend_to_keys(str,
|
130
|
-
change_key_text(
|
129
|
+
def prepend_to_keys(str, **)
|
130
|
+
change_key_text(**) do |key|
|
131
131
|
"#{str}#{key}"
|
132
132
|
end
|
133
133
|
end
|
@@ -150,8 +150,8 @@ module Darthjee
|
|
150
150
|
# @see KeyChanger#change_keys
|
151
151
|
#
|
152
152
|
# @example (see #prepend_to_keys)
|
153
|
-
def append_to_keys(str,
|
154
|
-
change_key_text(
|
153
|
+
def append_to_keys(str, **)
|
154
|
+
change_key_text(**) do |key|
|
155
155
|
"#{key}#{str}"
|
156
156
|
end
|
157
157
|
end
|
@@ -170,8 +170,8 @@ module Darthjee
|
|
170
170
|
# hash = { b: 1, a: 2 }
|
171
171
|
#
|
172
172
|
# hash.sort_keys # changes hash to { a: 2, b: 1 }
|
173
|
-
def sort_keys!(
|
174
|
-
Hash::KeysSorter.new(self, **
|
173
|
+
def sort_keys!(**)
|
174
|
+
Hash::KeysSorter.new(self, **).sort
|
175
175
|
end
|
176
176
|
|
177
177
|
# Sorts keys for hash without changing the original
|
@@ -188,8 +188,8 @@ module Darthjee
|
|
188
188
|
# hash = { b: 1, a: 2 }
|
189
189
|
#
|
190
190
|
# hash.sort_keys # returns { a: 2, b: 1 }
|
191
|
-
def sort_keys(
|
192
|
-
Hash::KeysSorter.new(deep_dup, **
|
191
|
+
def sort_keys(**)
|
192
|
+
Hash::KeysSorter.new(deep_dup, **).sort
|
193
193
|
end
|
194
194
|
|
195
195
|
# Changes the key of the hash without changing it
|
@@ -238,8 +238,8 @@ module Darthjee
|
|
238
238
|
# @return [::Hash]
|
239
239
|
#
|
240
240
|
# @see KeyChanger
|
241
|
-
def change_key_text(
|
242
|
-
Hash::KeyChanger.new(self).change_text(
|
241
|
+
def change_key_text(**, &)
|
242
|
+
Hash::KeyChanger.new(self).change_text(**, &)
|
243
243
|
end
|
244
244
|
end
|
245
245
|
end
|
@@ -61,11 +61,11 @@ module Darthjee
|
|
61
61
|
# # 'key_c' => 3
|
62
62
|
# # }
|
63
63
|
# # }
|
64
|
-
def change_keys(recursive: true, &
|
64
|
+
def change_keys(recursive: true, &)
|
65
65
|
if recursive
|
66
|
-
hash.deep_transform_keys!(&
|
66
|
+
hash.deep_transform_keys!(&)
|
67
67
|
else
|
68
|
-
hash.transform_keys!(&
|
68
|
+
hash.transform_keys!(&)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -92,10 +92,10 @@ module Darthjee
|
|
92
92
|
# changer = Darthjee::CoreExt::Hash::KeyChanger.new(hash)
|
93
93
|
# changer.camelize_keys
|
94
94
|
# hash # changed to { MyKey: { InnerKey: 10 } }
|
95
|
-
def camelize_keys(uppercase_first_letter: true, **
|
95
|
+
def camelize_keys(uppercase_first_letter: true, **)
|
96
96
|
type = uppercase_first_letter ? :upper : :lower
|
97
97
|
|
98
|
-
change_keys(
|
98
|
+
change_keys(**) do |key|
|
99
99
|
key.camelize(type)
|
100
100
|
end
|
101
101
|
end
|
@@ -117,8 +117,8 @@ module Darthjee
|
|
117
117
|
# changer.underscore_keys
|
118
118
|
#
|
119
119
|
# hash # changed to { my_key: { inner_key: 10 } }
|
120
|
-
def underscore_keys(
|
121
|
-
change_keys(
|
120
|
+
def underscore_keys(**)
|
121
|
+
change_keys(**, &:underscore)
|
122
122
|
end
|
123
123
|
|
124
124
|
# Change keys considering them to be strings
|
@@ -143,8 +143,8 @@ module Darthjee
|
|
143
143
|
# changer.change_text { |key| key.to_s.upcase }
|
144
144
|
#
|
145
145
|
# hash # changed to { KEY: { INNER_KEY: 10 } }
|
146
|
-
def change_text(type: :keep, **
|
147
|
-
change_keys(**
|
146
|
+
def change_text(type: :keep, **)
|
147
|
+
change_keys(**) do |key|
|
148
148
|
cast_new_key yield(key), key.class, type
|
149
149
|
end
|
150
150
|
end
|
@@ -169,9 +169,9 @@ module Darthjee
|
|
169
169
|
# @return [::String,::Symbol]
|
170
170
|
def cast_new_key(key, old_clazz, type)
|
171
171
|
case class_cast(old_clazz, type)
|
172
|
-
when :symbol
|
172
|
+
when :symbol
|
173
173
|
key.to_sym
|
174
|
-
when :string
|
174
|
+
when :string
|
175
175
|
key.to_s
|
176
176
|
end
|
177
177
|
end
|
@@ -192,6 +192,7 @@ module Darthjee
|
|
192
192
|
# @return [::Symbol]
|
193
193
|
def class_cast(old_clazz, type)
|
194
194
|
return type unless type == :keep
|
195
|
+
|
195
196
|
old_clazz.to_s.downcase.to_sym
|
196
197
|
end
|
197
198
|
end
|