turbo_test_ruby_refinements 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/.github/workflows/tests.yml +30 -0
- data/.gitignore +75 -0
- data/.rubocop.yml +54 -0
- data/.ruby-version +1 -0
- data/Appraisals +31 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/Makefile +46 -0
- data/README.md +83 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/turbo_test_ruby_refinements.rb +18 -0
- data/lib/turbo_test_ruby_refinements/gem_loaded_specs_paths.rb +17 -0
- data/lib/turbo_test_ruby_refinements/hash/deep_merge.rb +43 -0
- data/lib/turbo_test_ruby_refinements/hash/leaf_paths.rb +24 -0
- data/lib/turbo_test_ruby_refinements/module/class_variable_hash.rb +18 -0
- data/lib/turbo_test_ruby_refinements/module/instance_variable_hash.rb +18 -0
- data/lib/turbo_test_ruby_refinements/module/name.rb +65 -0
- data/lib/turbo_test_ruby_refinements/object/loaded_constants.rb +19 -0
- data/lib/turbo_test_ruby_refinements/string/json_parse.rb +20 -0
- data/lib/turbo_test_ruby_refinements/string/relative_path.rb +40 -0
- data/lib/turbo_test_ruby_refinements/string/test_file.rb +19 -0
- data/lib/turbo_test_ruby_refinements/version.rb +5 -0
- data/turbo_test_ruby_refinements.gemspec +30 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d74bbb1481edf355fc27a84fc71efedbb2cc03d0e322c6fb11f5d5bc63d2eaa7
|
4
|
+
data.tar.gz: 1420039e93cb952d83a0068a75bd8c31067a9b6bfffe7ff1ef9862e8ad785a86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f48b56fa321870d810107d792fd32429601265a7bd2648e5d9cb888ed188b334d329021b7dc3bf84faaced0c25fe3a703d7127921a7da8b51d89e0aec41c668b
|
7
|
+
data.tar.gz: 87541e12ecda78c83f0dd393e46cea72828d4de75db25b5abe2626a073c5f9bf62fc5c3fea6c412ebc4aa3fe6792b361a9e648e2b856c54eb2436858b28ca52d
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: >-
|
8
|
+
Ruby: ${{ matrix.ruby }}
|
9
|
+
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.4', '2.5', '2.6', '2.7' ]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
|
23
|
+
- name: Install dependencies
|
24
|
+
run: |
|
25
|
+
bundle config path vendor/bundle
|
26
|
+
bundle install --binstubs --jobs 4 --retry 3
|
27
|
+
|
28
|
+
- name: Run tests
|
29
|
+
run: |
|
30
|
+
bundle exec rake
|
data/.gitignore
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
*.gem
|
11
|
+
*.rbc
|
12
|
+
/.config
|
13
|
+
/coverage/
|
14
|
+
/InstalledFiles
|
15
|
+
/pkg/
|
16
|
+
/spec/reports/
|
17
|
+
/spec/examples.txt
|
18
|
+
/test/tmp/
|
19
|
+
/test/version_tmp/
|
20
|
+
/tmp/
|
21
|
+
|
22
|
+
# Used by dotenv library to load environment variables.
|
23
|
+
# .env
|
24
|
+
|
25
|
+
## Specific to RubyMotion:
|
26
|
+
.dat*
|
27
|
+
.repl_history
|
28
|
+
build/
|
29
|
+
*.bridgesupport
|
30
|
+
build-iPhoneOS/
|
31
|
+
build-iPhoneSimulator/
|
32
|
+
|
33
|
+
.DS_Store
|
34
|
+
|
35
|
+
## Specific to RubyMotion (use of CocoaPods):
|
36
|
+
#
|
37
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
38
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
39
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
40
|
+
#
|
41
|
+
# vendor/Pods/
|
42
|
+
|
43
|
+
## Documentation cache and generated files:
|
44
|
+
/.yardoc/
|
45
|
+
/_yardoc/
|
46
|
+
/doc/
|
47
|
+
/rdoc/
|
48
|
+
|
49
|
+
## Environment normalization:
|
50
|
+
/.bundle/
|
51
|
+
/vendor/bundle
|
52
|
+
/lib/bundler/man/
|
53
|
+
|
54
|
+
# for a library or gem, you might want to ignore these files since the code is
|
55
|
+
# intended to run in multiple environments; otherwise, check them in:
|
56
|
+
# Gemfile.lock
|
57
|
+
# .ruby-version
|
58
|
+
# .ruby-gemset
|
59
|
+
|
60
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
61
|
+
.rvmrc
|
62
|
+
|
63
|
+
#SAM artifacts
|
64
|
+
/packaged.yaml
|
65
|
+
|
66
|
+
.byebug_history
|
67
|
+
|
68
|
+
lib/rts/*bundle
|
69
|
+
lib/ext/*bundle
|
70
|
+
|
71
|
+
ext/rts/Makefile
|
72
|
+
/test/support/files/db.sqlite3
|
73
|
+
/.turbotest.yml
|
74
|
+
/test/support/projects/*/bin
|
75
|
+
/test/support/projects/*/Gemfile.lock
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
4
|
+
ExtraDetails: true
|
5
|
+
NewCops: enable
|
6
|
+
TargetRubyVersion: 2.7
|
7
|
+
Exclude:
|
8
|
+
- Gemfile
|
9
|
+
- "**/*.gemfile"
|
10
|
+
- bin/*
|
11
|
+
- "*.gemspec"
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Enabled: true
|
15
|
+
AutoCorrect: false
|
16
|
+
Max: 100
|
17
|
+
|
18
|
+
Lint/Void:
|
19
|
+
Exclude:
|
20
|
+
- test/object/object_loaded_constants_test.rb
|
21
|
+
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Exclude:
|
24
|
+
- test/**/*_test.rb
|
25
|
+
|
26
|
+
Metrics/ClassLength:
|
27
|
+
Exclude:
|
28
|
+
- test/**/*
|
29
|
+
- lib/tasks/*
|
30
|
+
|
31
|
+
Metrics/MethodLength:
|
32
|
+
Max: 10
|
33
|
+
|
34
|
+
Style/ClassAndModuleChildren:
|
35
|
+
Exclude:
|
36
|
+
- test/**/*
|
37
|
+
|
38
|
+
Style/ClassVars:
|
39
|
+
Exclude:
|
40
|
+
- test/module/module_class_variable_hash_test.rb
|
41
|
+
|
42
|
+
Style/Documentation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/RedundantBegin:
|
46
|
+
Exclude:
|
47
|
+
- lib/turbo_test_ruby_refinements/module/class_variable_hash.rb
|
48
|
+
- lib/turbo_test_ruby_refinements/module/instance_variable_hash.rb
|
49
|
+
|
50
|
+
Style/StringLiterals:
|
51
|
+
Enabled: true
|
52
|
+
EnforcedStyle: double_quotes
|
53
|
+
ConsistentQuotesInMultiline: true
|
54
|
+
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/Appraisals
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
case RUBY_VERSION
|
4
|
+
when ->(n) { n > "2.7" }
|
5
|
+
appraise "ruby-2.7.x" do
|
6
|
+
ruby "2.7.1"
|
7
|
+
gem "simplecov"
|
8
|
+
gem "byebug"
|
9
|
+
gem "rubocop"
|
10
|
+
end
|
11
|
+
when ->(n) { n > "2.6" }
|
12
|
+
appraise "ruby-2.6.6" do
|
13
|
+
ruby "2.6.6"
|
14
|
+
gem "byebug"
|
15
|
+
end
|
16
|
+
when ->(n) { n > "2.5" }
|
17
|
+
appraise "ruby-2.5.8" do
|
18
|
+
ruby "2.5.8"
|
19
|
+
gem "byebug"
|
20
|
+
end
|
21
|
+
when ->(n) { n > "2.4" }
|
22
|
+
appraise "ruby-2.4.10" do
|
23
|
+
ruby "2.4.10"
|
24
|
+
gem "byebug"
|
25
|
+
end
|
26
|
+
when ->(n) { n > "2.3" }
|
27
|
+
appraise "ruby-2.3.8" do
|
28
|
+
ruby "2.3.8"
|
29
|
+
gem "byebug", "~> 11.0.1"
|
30
|
+
end
|
31
|
+
end
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at marcessindi@icloud.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
turbo-test-ruby-refinements (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
byebug (11.1.3)
|
11
|
+
docile (1.3.2)
|
12
|
+
minitest (5.14.1)
|
13
|
+
mocha (1.11.2)
|
14
|
+
parallel (1.19.2)
|
15
|
+
parser (2.7.1.4)
|
16
|
+
ast (~> 2.4.1)
|
17
|
+
rainbow (3.0.0)
|
18
|
+
rake (13.0.1)
|
19
|
+
regexp_parser (1.7.1)
|
20
|
+
rexml (3.2.4)
|
21
|
+
rubocop (0.88.0)
|
22
|
+
parallel (~> 1.10)
|
23
|
+
parser (>= 2.7.1.1)
|
24
|
+
rainbow (>= 2.2.2, < 4.0)
|
25
|
+
regexp_parser (>= 1.7)
|
26
|
+
rexml
|
27
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
28
|
+
ruby-progressbar (~> 1.7)
|
29
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
30
|
+
rubocop-ast (0.3.0)
|
31
|
+
parser (>= 2.7.1.4)
|
32
|
+
ruby-progressbar (1.10.1)
|
33
|
+
simplecov (0.18.5)
|
34
|
+
docile (~> 1.1)
|
35
|
+
simplecov-html (~> 0.11)
|
36
|
+
simplecov-html (0.12.2)
|
37
|
+
unicode-display_width (1.7.0)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
byebug
|
44
|
+
minitest
|
45
|
+
mocha
|
46
|
+
rake
|
47
|
+
rubocop
|
48
|
+
simplecov
|
49
|
+
turbo-test-ruby-refinements!
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Marcos Essindi
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Adapted from https://github.com/zspencer/make-many-rubies/blob/master/Makefile
|
2
|
+
|
3
|
+
# Allows running (and re-running) of tests against several ruby versions,
|
4
|
+
# assuming you use rbenv instead of rvm.
|
5
|
+
|
6
|
+
# Uses pattern rules (task-$:) and automatic variables ($*).
|
7
|
+
# Pattern rules: http://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html#SEC98
|
8
|
+
# Automatic variables: http://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_10.html#SEC101
|
9
|
+
|
10
|
+
# Rbenv-friendly version identifiers for supported Rubys
|
11
|
+
23_version = 2.3.8
|
12
|
+
24_version = 2.4.10
|
13
|
+
25_version = 2.5.8
|
14
|
+
26_version = 2.6.6
|
15
|
+
27_version = 2.7.1
|
16
|
+
|
17
|
+
# The ruby version for use in a given rule.
|
18
|
+
# Requires a matched pattern rule and a supported ruby version.
|
19
|
+
#
|
20
|
+
# Given a pattern rule defined as "install-ruby-%"
|
21
|
+
# When the rule is ran as "install-ruby-193"
|
22
|
+
# Then the inner addsuffix call evaluates to "193_version"
|
23
|
+
# And given_ruby_version becomes "1.9.3-p551"
|
24
|
+
given_ruby_version = $($(addsuffix _version, $*))
|
25
|
+
|
26
|
+
# Instruct rbenv on which Ruby version to use when running a command.
|
27
|
+
# Requires a pattern rule and a supported ruby version.
|
28
|
+
#
|
29
|
+
# Given a pattern rule defined as "test-%"
|
30
|
+
# When the rule is ran as "test-187"
|
31
|
+
# Then with_given_ruby becomes "RBENV_VERSION=1.8.7-p375"
|
32
|
+
with_given_ruby = RBENV_VERSION=$(given_ruby_version)
|
33
|
+
|
34
|
+
|
35
|
+
# Runs tests for all supported ruby versions.
|
36
|
+
test: test-24 test-25 test-26 test-27
|
37
|
+
test_23: test-23
|
38
|
+
test_24: test-24
|
39
|
+
test_25: test-25
|
40
|
+
test_26: test-26
|
41
|
+
test_27: test-27
|
42
|
+
|
43
|
+
# Runs tests against a specific ruby version
|
44
|
+
test-%:
|
45
|
+
$(with_given_ruby) bundle install
|
46
|
+
$(with_given_ruby) bundle exec rake
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# TurboTestRubyRefinements
|
2
|
+
|
3
|
+
Collection of refinements for Ruby classes:
|
4
|
+
|
5
|
+
- TurboTestRubyRefinements::HashDeepMerge (Hash)
|
6
|
+
|
7
|
+
```#deep_merge``` from ActiveSupport
|
8
|
+
```#deep_merge!``` from ActiveSupport
|
9
|
+
- TurboTestRubyRefinements::HashLeafPaths (Hash)
|
10
|
+
|
11
|
+
```#leaf_paths```: returns an array with a list of nested keys in the hash
|
12
|
+
|
13
|
+
- TurboTestRubyRefinements::ModuleName (Module)
|
14
|
+
|
15
|
+
```#turbo_test_name```: resolves singleton and anonymous class names.
|
16
|
+
|
17
|
+
- TurboTestRubyRefinements::InstanceVariableHash (Module)
|
18
|
+
|
19
|
+
```#instance_variable_hash```
|
20
|
+
- TurboTestRubyRefinements::ClassVariableHash (Module)
|
21
|
+
|
22
|
+
```#class_variable_hash```
|
23
|
+
|
24
|
+
- TurboTestRubyRefinements::ObjectLoadedConstants (Object)
|
25
|
+
|
26
|
+
```#loaded_constants```
|
27
|
+
|
28
|
+
- TurboTestRubyRefinements::StringJSONParse (String)
|
29
|
+
|
30
|
+
```#parse_as_json```
|
31
|
+
|
32
|
+
- TurboTestRubyRefinements::StringRelativePath (String)
|
33
|
+
|
34
|
+
```#relative_path```
|
35
|
+
|
36
|
+
- TurboTestRubyRefinements::StringTestFile (String)
|
37
|
+
|
38
|
+
```#test_file?```
|
39
|
+
|
40
|
+
- TurboTestRubyRefinements::GemLoadedSpecsPaths (Gem)
|
41
|
+
|
42
|
+
```#loaded_specs_paths```
|
43
|
+
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
Add this line to your application's Gemfile:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
gem 'turbo_test_ruby_refinements'
|
51
|
+
```
|
52
|
+
|
53
|
+
And then execute:
|
54
|
+
|
55
|
+
$ bundle install
|
56
|
+
|
57
|
+
Or install it yourself as:
|
58
|
+
|
59
|
+
$ gem install turbo_test_ruby_refinements
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
Activate the refinements you want to use at the top-level, and inside classes and modules.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
using TurboTestRubyRefinements::StringRelativePath
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
[Refinements Documentation](https://ruby-doc.org/core-2.7.1/doc/syntax/refinements_rdoc.html)
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dunkelbraun/turbo_test_ruby_refinements. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dunkelbraun/turbo_test_ruby_refinements/blob/master/CODE_OF_CONDUCT.md).
|
75
|
+
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
## Code of Conduct
|
82
|
+
|
83
|
+
Everyone interacting in the TurboTestRubyRefinements project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dunkelbraun/turbo_test_ruby_refinements/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
ENV["TESTOPTS"] = "#{ENV['TESTOPTS']} --verbose"
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.libs << "lib"
|
11
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "turbo_test_ruby_refinements"
|
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,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "turbo_test_ruby_refinements/version"
|
4
|
+
|
5
|
+
require_relative "turbo_test_ruby_refinements/string/relative_path"
|
6
|
+
require_relative "turbo_test_ruby_refinements/string/test_file"
|
7
|
+
require_relative "turbo_test_ruby_refinements/string/json_parse"
|
8
|
+
|
9
|
+
require_relative "turbo_test_ruby_refinements/hash/deep_merge"
|
10
|
+
require_relative "turbo_test_ruby_refinements/hash/leaf_paths"
|
11
|
+
|
12
|
+
require_relative "turbo_test_ruby_refinements/module/name"
|
13
|
+
require_relative "turbo_test_ruby_refinements/module/class_variable_hash"
|
14
|
+
require_relative "turbo_test_ruby_refinements/module/instance_variable_hash"
|
15
|
+
|
16
|
+
require_relative "turbo_test_ruby_refinements/object/loaded_constants"
|
17
|
+
|
18
|
+
require_relative "turbo_test_ruby_refinements/gem_loaded_specs_paths"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module GemLoadedSpecsPaths
|
5
|
+
class << self
|
6
|
+
attr_accessor :path_cache
|
7
|
+
end
|
8
|
+
|
9
|
+
refine ::Gem.singleton_class do
|
10
|
+
def loaded_specs_paths
|
11
|
+
GemLoadedSpecsPaths.path_cache ||= loaded_specs.each_with_object([]) do |spec, memo|
|
12
|
+
memo << spec[1].full_gem_path
|
13
|
+
end.sort!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module HashDeepMerge
|
5
|
+
refine ::Hash do
|
6
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
7
|
+
#
|
8
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
9
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
10
|
+
#
|
11
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
12
|
+
#
|
13
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
14
|
+
# to merge values:
|
15
|
+
#
|
16
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
17
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
18
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
19
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
20
|
+
def deep_merge(other_hash, &block)
|
21
|
+
dup.deep_merge!(other_hash, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Same as +deep_merge+, but modifies +self+.
|
25
|
+
def deep_merge!(other_hash, &block)
|
26
|
+
merge!(other_hash) do |key, this_val, other_val|
|
27
|
+
# We can't use use this.val.is_a?(Hash) because inside the refinement
|
28
|
+
# returns false:
|
29
|
+
# - refined_hash.class != Hash
|
30
|
+
if this_val.class.name == "Hash" && other_val.class.name == "Hash"
|
31
|
+
this_val.deep_merge(other_val, &block)
|
32
|
+
elsif block_given?
|
33
|
+
block.call(key, this_val, other_val)
|
34
|
+
else
|
35
|
+
other_val
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# From: https://github.com/rails/rails/blob/v6.0.3.2/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module HashLeafPaths
|
5
|
+
refine ::Hash.singleton_class do
|
6
|
+
# Returns an array with a list of nested keys in the hash
|
7
|
+
#
|
8
|
+
# h = { key1: "1", key2: "2", key3: { key4: { key41: "3", key42: "4" }
|
9
|
+
# h.leaf_paths => [ "key1", "key2", "key3.key4.key41", "key3.key4.key42" ]
|
10
|
+
def leaf_paths(hash = {}, memo = [], scope = [])
|
11
|
+
unless hash.is_a?(Hash)
|
12
|
+
memo << scope.join(".")
|
13
|
+
scope.pop
|
14
|
+
return
|
15
|
+
end
|
16
|
+
hash.each_key do |key|
|
17
|
+
leaf_paths(hash[key], memo, scope << key)
|
18
|
+
scope.pop if scope.last == key
|
19
|
+
end
|
20
|
+
memo
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module ClassVariableHash
|
5
|
+
refine ::Module do
|
6
|
+
def class_variable_hash
|
7
|
+
class_variables.each_with_object({}) do |class_variable, memo|
|
8
|
+
begin
|
9
|
+
memo[class_variable] = class_variable_get(class_variable).object_id
|
10
|
+
rescue StandardError
|
11
|
+
# Autoloaded classes may list class variables, but can raise an exception when
|
12
|
+
# trying to access them if the class is is not fully loaded (ie. when tracing code)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module InstanceVariableHash
|
5
|
+
refine ::Module do
|
6
|
+
def instance_variable_hash
|
7
|
+
instance_variables.each_with_object({}) do |instance_variable, memo|
|
8
|
+
begin
|
9
|
+
memo[instance_variable] = instance_variable_get(instance_variable).object_id
|
10
|
+
rescue StandardError
|
11
|
+
# Autoloaded classes may list instance variables, but can raise an exception when
|
12
|
+
# trying to access them if the class is is not fully loaded (ie. when tracing code)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fiddle"
|
4
|
+
|
5
|
+
module TurboTestRubyRefinements
|
6
|
+
module ModuleName
|
7
|
+
ANONYMOUS_CLASS_MATCHER = /(#<Class:(0x\w+)>)/.freeze
|
8
|
+
|
9
|
+
refine ::Module do
|
10
|
+
# Resolves singleton class names to the name of the class
|
11
|
+
#
|
12
|
+
# class AClass;end
|
13
|
+
# AClass.singleton_class.name
|
14
|
+
# => "#<Class:AClass>"
|
15
|
+
# AClass.turbo_test_name
|
16
|
+
# => "AClass"
|
17
|
+
#
|
18
|
+
# anonymous = class << AClass; class SomeClass; self; end; end
|
19
|
+
# anonymous.name
|
20
|
+
# => "#<Class:0x00007fd72a1bce30>::SomeClass"
|
21
|
+
# anonymous.turbo_test_name
|
22
|
+
# => "AClass::SomeClass"
|
23
|
+
def turbo_test_name
|
24
|
+
return translated_name unless singleton_class?
|
25
|
+
|
26
|
+
obj = ObjectSpace.each_object(self).first
|
27
|
+
case obj
|
28
|
+
when Module
|
29
|
+
obj.turbo_test_name
|
30
|
+
else
|
31
|
+
obj.class.turbo_test_name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns either self for a class or the class from which a class is the singleton class
|
36
|
+
#
|
37
|
+
# class AClass;end
|
38
|
+
# AClass.singleton_class.name
|
39
|
+
# => Class
|
40
|
+
# AClass.singleton_class.turbo_test_original_class
|
41
|
+
# => AClass
|
42
|
+
def turbo_test_original_class
|
43
|
+
return self unless singleton_class?
|
44
|
+
|
45
|
+
obj = ObjectSpace.each_object(self).first
|
46
|
+
case obj
|
47
|
+
when Module
|
48
|
+
obj.turbo_test_original_class
|
49
|
+
else
|
50
|
+
obj.class.turbo_test_original_class
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def translated_name
|
55
|
+
return if name.nil?
|
56
|
+
|
57
|
+
name.gsub(TurboTestRubyRefinements::ModuleName::ANONYMOUS_CLASS_MATCHER) do |_match|
|
58
|
+
obj = Fiddle::Pointer.new(Integer(Regexp.last_match(2))).to_value
|
59
|
+
obj.turbo_test_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
private :translated_name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module ObjectLoadedConstants
|
5
|
+
module Methods
|
6
|
+
def loaded_constants
|
7
|
+
constants.find_all { |constant| self.autoload?(constant).nil? }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
refine ::Object.singleton_class do
|
12
|
+
include Methods
|
13
|
+
end
|
14
|
+
|
15
|
+
refine ::Module do
|
16
|
+
include Methods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module TurboTestRubyRefinements
|
6
|
+
module StringJSONParse
|
7
|
+
refine ::String do
|
8
|
+
def parse_as_json(symbolize_names: false)
|
9
|
+
JSON.parse self, symbolize_names: symbolize_names
|
10
|
+
rescue JSON::ParserError
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
refine ::NilClass do
|
15
|
+
def parse_as_json(*)
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module TurboTestRubyRefinements
|
6
|
+
module StringRelativePath
|
7
|
+
class << self
|
8
|
+
def fetch(key)
|
9
|
+
@path_cache ||= {}
|
10
|
+
return @path_cache[key] if @path_cache.key?(key)
|
11
|
+
|
12
|
+
@path_cache[key] = yield
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_root_path
|
16
|
+
@app_root_path ||= Pathname.new(Dir.pwd)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
refine ::String do
|
21
|
+
def relative_path
|
22
|
+
StringRelativePath.fetch(self) do
|
23
|
+
path = Pathname.new(self)
|
24
|
+
return self unless path.exist?
|
25
|
+
|
26
|
+
unless path.relative?
|
27
|
+
path = path.realpath.relative_path_from(StringRelativePath.app_root_path)
|
28
|
+
end
|
29
|
+
path.cleanpath.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
refine ::NilClass do
|
35
|
+
def relative_path
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TurboTestRubyRefinements
|
4
|
+
module StringTestFile
|
5
|
+
TEST_MATCHER = /^(.+\.feature|.+_spec.rb|.+_test\.rb)$/.freeze
|
6
|
+
|
7
|
+
refine ::String do
|
8
|
+
def test_file?
|
9
|
+
!match(TEST_MATCHER).nil?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
refine ::NilClass do
|
14
|
+
def test_file?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative "lib/turbo_test_ruby_refinements/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "turbo_test_ruby_refinements"
|
5
|
+
spec.version = TurboTestRubyRefinements::VERSION
|
6
|
+
spec.authors = ["Marcos Essindi"]
|
7
|
+
spec.email = ["marcessindi@icloud.com"]
|
8
|
+
|
9
|
+
spec.summary = "Collection of refinements for Ruby classes"
|
10
|
+
spec.homepage = "https://github.com/dunkelbraun/turbo-test-ruby-refinements"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
13
|
+
|
14
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/dunkelbraun/turbo-test-ruby-refinements"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.14.1"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turbo_test_ruby_refinements
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcos Essindi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.14.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.14.1
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- marcessindi@icloud.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".github/workflows/tests.yml"
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".ruby-version"
|
52
|
+
- Appraisals
|
53
|
+
- CODE_OF_CONDUCT.md
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- Makefile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/console
|
61
|
+
- bin/setup
|
62
|
+
- lib/turbo_test_ruby_refinements.rb
|
63
|
+
- lib/turbo_test_ruby_refinements/gem_loaded_specs_paths.rb
|
64
|
+
- lib/turbo_test_ruby_refinements/hash/deep_merge.rb
|
65
|
+
- lib/turbo_test_ruby_refinements/hash/leaf_paths.rb
|
66
|
+
- lib/turbo_test_ruby_refinements/module/class_variable_hash.rb
|
67
|
+
- lib/turbo_test_ruby_refinements/module/instance_variable_hash.rb
|
68
|
+
- lib/turbo_test_ruby_refinements/module/name.rb
|
69
|
+
- lib/turbo_test_ruby_refinements/object/loaded_constants.rb
|
70
|
+
- lib/turbo_test_ruby_refinements/string/json_parse.rb
|
71
|
+
- lib/turbo_test_ruby_refinements/string/relative_path.rb
|
72
|
+
- lib/turbo_test_ruby_refinements/string/test_file.rb
|
73
|
+
- lib/turbo_test_ruby_refinements/version.rb
|
74
|
+
- turbo_test_ruby_refinements.gemspec
|
75
|
+
homepage: https://github.com/dunkelbraun/turbo-test-ruby-refinements
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
homepage_uri: https://github.com/dunkelbraun/turbo-test-ruby-refinements
|
80
|
+
source_code_uri: https://github.com/dunkelbraun/turbo-test-ruby-refinements
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.4.0
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.1.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Collection of refinements for Ruby classes
|
100
|
+
test_files: []
|