wc-essentials 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.devcontainer/Dockerfile +21 -0
- data/.devcontainer/devcontainer.json +32 -0
- data/.devcontainer/postCreateCommands.sh +13 -0
- data/.github/workflows/coverage.yml +99 -0
- data/.github/workflows/publish-gem.yml +25 -0
- data/.github/workflows/test-base.yml +34 -0
- data/.github/workflows/test-essentials.yml +33 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +71 -0
- data/API.md +50 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.md +21 -0
- data/README.md +20 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/wc/essentials/class_helpers.rb +67 -0
- data/lib/wc/essentials/class_registers.rb +53 -0
- data/lib/wc/essentials/count_tracker.rb +43 -0
- data/lib/wc/essentials/version.rb +7 -0
- data/lib/wc/essentials.rb +17 -0
- data/wc-essentials.gemspec +54 -0
- metadata +181 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0dd4d39d4c354a2e5f17a597a8a3314dcdac40903d37f60f646750fd5a7a7c41
|
4
|
+
data.tar.gz: 4c7fbc1e7c2175138bbc2ebc5d2634c917b44817885bcbdcf6b6ba1e4deac169
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bfe39ee38cd378815ac78a253f0d901c6d4c6676c11907f95cc7693d3765d38dceec390567292235bbe79a7f9862e7fd41f2065ee3de2b741e15332a04efddf
|
7
|
+
data.tar.gz: 16ccae333ee7921a662eb525106e933b398830af04612967400803f9b9cc78bbd42a7b08a41d57588a582096a3d6f2de8f0aecdf79549fc8f50c262da44577c9
|
@@ -0,0 +1,21 @@
|
|
1
|
+
FROM workcompass/wc-rails:1.1.0
|
2
|
+
LABEL maintainer="Dev Team at WorkCompass <dev@workcompass.com>"
|
3
|
+
ENV REFRESHED_ON 2021-08-08
|
4
|
+
|
5
|
+
# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
|
6
|
+
# The value is a comma-separated list of allowed domains
|
7
|
+
ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev"
|
8
|
+
|
9
|
+
# [Choice] Node.js version: lts/*, 16, 14, 12, 10
|
10
|
+
# ARG NODE_VERSION="lts/*"
|
11
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"
|
12
|
+
|
13
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
14
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
15
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
16
|
+
|
17
|
+
# [Optional] Uncomment this line to install additional gems.
|
18
|
+
# RUN gem install <your-gem-names-here>
|
19
|
+
|
20
|
+
# [Optional] Uncomment this line to install global node packages.
|
21
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.224.3/containers/ruby-rails
|
3
|
+
{
|
4
|
+
"name": "wc-essentials",
|
5
|
+
"build": {
|
6
|
+
"dockerfile": "Dockerfile"
|
7
|
+
},
|
8
|
+
|
9
|
+
// Set *default* container specific settings.json values on container create.
|
10
|
+
"settings": {},
|
11
|
+
|
12
|
+
// Add the IDs of extensions you want installed when the container is created.
|
13
|
+
"extensions": [
|
14
|
+
"rebornix.Ruby",
|
15
|
+
"ms-vscode.test-adapter-converter",
|
16
|
+
"connorshea.vscode-ruby-test-adapter",
|
17
|
+
"misogi.ruby-rubocop",
|
18
|
+
"eamodio.gitlens",
|
19
|
+
"ms-vsliveshare.vsliveshare"
|
20
|
+
],
|
21
|
+
|
22
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
23
|
+
// "forwardPorts": [],
|
24
|
+
|
25
|
+
// Use 'onCreateCommand' to run commands once the container is created.
|
26
|
+
"onCreateCommand": "bundle install",
|
27
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
28
|
+
"postCreateCommand": "chmod +x ./.devcontainer/postCreateCommands.sh && ./.devcontainer/postCreateCommands.sh"
|
29
|
+
|
30
|
+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
31
|
+
// "remoteUser": "vscode"
|
32
|
+
}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
name: Coverage
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
types:
|
10
|
+
- ready_for_review
|
11
|
+
- auto_merge_enabled
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test-base:
|
15
|
+
# Containers must run in Linux based operating systems
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
# Docker Hub image that `container-job` executes in
|
18
|
+
container: workcompass/wc-rails-ci:1.1.0
|
19
|
+
|
20
|
+
steps:
|
21
|
+
# Downloads a copy of the code in your repository before running CI tests
|
22
|
+
- name: Check out repository code
|
23
|
+
uses: actions/checkout@v3
|
24
|
+
|
25
|
+
- name: Install gems
|
26
|
+
run: bundle install
|
27
|
+
|
28
|
+
- name: Run rspec test base
|
29
|
+
env:
|
30
|
+
RAILS_ENV: test
|
31
|
+
SIMPLECOV: true
|
32
|
+
run: bundle exec rspec spec/wc/essentials_spec.rb
|
33
|
+
|
34
|
+
- name: Upload to AWS
|
35
|
+
env:
|
36
|
+
AWS_ACCESS_KEY_ID: ${{ secrets.COVERAGE_AWS_ACCESS_KEY_ID }}
|
37
|
+
AWS_SECRET_ACCESS_KEY: ${{ secrets.COVERAGE_AWS_SECRET_ACCESS_KEY }}
|
38
|
+
AWS_DEFAULT_REGION: eu-west-1
|
39
|
+
run: |
|
40
|
+
aws s3 cp coverage/.resultset.json s3://wc-cov-codeclimate/${{ github.repository }}/${{ github.ref }}/codeclimate.base.json
|
41
|
+
|
42
|
+
test-essentials:
|
43
|
+
# Containers must run in Linux based operating systems
|
44
|
+
runs-on: ubuntu-latest
|
45
|
+
# Docker Hub image that `container-job` executes in
|
46
|
+
container: workcompass/wc-rails-ci:1.1.0
|
47
|
+
|
48
|
+
steps:
|
49
|
+
# Downloads a copy of the code in your repository before running CI tests
|
50
|
+
- name: Check out repository code
|
51
|
+
uses: actions/checkout@v3
|
52
|
+
|
53
|
+
- name: Install gems
|
54
|
+
run: bundle install
|
55
|
+
|
56
|
+
- name: Run rspec test base
|
57
|
+
env:
|
58
|
+
RAILS_ENV: test
|
59
|
+
SIMPLECOV: true
|
60
|
+
run: bundle exec rspec spec/wc/essentials/
|
61
|
+
|
62
|
+
- name: Upload to AWS
|
63
|
+
env:
|
64
|
+
AWS_ACCESS_KEY_ID: ${{ secrets.COVERAGE_AWS_ACCESS_KEY_ID }}
|
65
|
+
AWS_SECRET_ACCESS_KEY: ${{ secrets.COVERAGE_AWS_SECRET_ACCESS_KEY }}
|
66
|
+
AWS_DEFAULT_REGION: eu-west-1
|
67
|
+
run: |
|
68
|
+
aws s3 cp coverage/.resultset.json s3://wc-cov-codeclimate/${{ github.repository }}/${{ github.ref }}/codeclimate.essentials.json
|
69
|
+
|
70
|
+
codeclimate-coverage:
|
71
|
+
needs:
|
72
|
+
- test-base
|
73
|
+
- test-essentials
|
74
|
+
|
75
|
+
# Containers must run in Linux based operating systems
|
76
|
+
runs-on: ubuntu-latest
|
77
|
+
# Docker Hub image that `container-job` executes in
|
78
|
+
container: workcompass/wc-rails-ci:1.1.0
|
79
|
+
|
80
|
+
steps:
|
81
|
+
# Downloads a copy of the code in your repository before running CI tests
|
82
|
+
- name: Check out repository code
|
83
|
+
uses: actions/checkout@v3
|
84
|
+
|
85
|
+
- name: Download coverage reports
|
86
|
+
shell: bash
|
87
|
+
env:
|
88
|
+
AWS_ACCESS_KEY_ID: ${{ secrets.COVERAGE_AWS_ACCESS_KEY_ID }}
|
89
|
+
AWS_SECRET_ACCESS_KEY: ${{ secrets.COVERAGE_AWS_SECRET_ACCESS_KEY }}
|
90
|
+
AWS_DEFAULT_REGION: eu-west-1
|
91
|
+
run: /usr/local/bin/aws s3 cp s3://wc-cov-codeclimate/${{ github.repository }}/${{ github.ref }} cov/ --recursive
|
92
|
+
|
93
|
+
- name: Combine & Publish code coverage
|
94
|
+
uses: paambaati/codeclimate-action@v3.2.0
|
95
|
+
env:
|
96
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
97
|
+
with:
|
98
|
+
coverageLocations: |
|
99
|
+
${{ github.workspace }}/cov/codeclimate.*.json:simplecov
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- '*'
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
# Downloads a copy of the code in your repository before running CI tests
|
13
|
+
- name: Check out repository code
|
14
|
+
uses: actions/checkout@v3
|
15
|
+
|
16
|
+
- name: Publish to RubyGems
|
17
|
+
env:
|
18
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
|
19
|
+
run: |
|
20
|
+
mkdir -p $HOME/.gem
|
21
|
+
touch $HOME/.gem/credentials
|
22
|
+
chmod 0600 $HOME/.gem/credentials
|
23
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
24
|
+
gem build *.gemspec
|
25
|
+
gem push *.gem
|
@@ -0,0 +1,34 @@
|
|
1
|
+
name: Test Base
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- '*' # matches every branch that doesn't contain a '/'
|
7
|
+
- '*/*' # matches every branch containing a single '/'
|
8
|
+
- '**' # matches every branch
|
9
|
+
- '!master' # includes master
|
10
|
+
paths:
|
11
|
+
- 'lib/wc/essentials.rb'
|
12
|
+
- 'lib/wc/essentials/version.rb'
|
13
|
+
- 'spec/wc/essentials_spec.rb'
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
# Label of the container job
|
17
|
+
test-base:
|
18
|
+
# Containers must run in Linux based operating systems
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
# Docker Hub image that `container-job` executes in
|
21
|
+
container: workcompass/wc-rails-ci:1.1.0
|
22
|
+
|
23
|
+
steps:
|
24
|
+
# Downloads a copy of the code in your repository before running CI tests
|
25
|
+
- name: Check out repository code
|
26
|
+
uses: actions/checkout@v3
|
27
|
+
|
28
|
+
- name: Install gems
|
29
|
+
run: bundle install
|
30
|
+
|
31
|
+
- name: Run rspec test wc-essentials
|
32
|
+
run: >
|
33
|
+
bundle exec rspec
|
34
|
+
spec/wc/essentials_spec.rb
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- '*' # matches every branch that doesn't contain a '/'
|
7
|
+
- '*/*' # matches every branch containing a single '/'
|
8
|
+
- '**' # matches every branch
|
9
|
+
- '!master' # includes master
|
10
|
+
paths:
|
11
|
+
- 'lib/wc/essentials/**/*'
|
12
|
+
- 'spec/wc/essentials/**/*'
|
13
|
+
|
14
|
+
jobs:
|
15
|
+
# Label of the container job
|
16
|
+
test-essentials:
|
17
|
+
# Containers must run in Linux based operating systems
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
# Docker Hub image that `container-job` executes in
|
20
|
+
container: workcompass/wc-rails-ci:1.1.0
|
21
|
+
|
22
|
+
steps:
|
23
|
+
# Downloads a copy of the code in your repository before running CI tests
|
24
|
+
- name: Check out repository code
|
25
|
+
uses: actions/checkout@v3
|
26
|
+
|
27
|
+
- name: Install gems
|
28
|
+
run: bundle install
|
29
|
+
|
30
|
+
- name: Run rspec test wc-essentials
|
31
|
+
run: >
|
32
|
+
bundle exec rspec
|
33
|
+
spec/wc/essentials/
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Enabled: true
|
6
|
+
Max: 90
|
7
|
+
Exclude:
|
8
|
+
- bin/**/*
|
9
|
+
- spec/**/*
|
10
|
+
|
11
|
+
Lint/AmbiguousBlockAssociation:
|
12
|
+
Enabled: true
|
13
|
+
Exclude:
|
14
|
+
- spec/**/*
|
15
|
+
|
16
|
+
Lint/RaiseException:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/StructNewOverride:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Enabled: true
|
24
|
+
Exclude:
|
25
|
+
- spec/**/*
|
26
|
+
- wc-essentials.gemspec
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Enabled: true
|
30
|
+
Max: 17
|
31
|
+
|
32
|
+
Naming/VariableNumber:
|
33
|
+
Enabled: true
|
34
|
+
Exclude:
|
35
|
+
- spec/**/*
|
36
|
+
|
37
|
+
Style/BlockDelimiters:
|
38
|
+
Enabled: true
|
39
|
+
Exclude:
|
40
|
+
- spec/**/*
|
41
|
+
|
42
|
+
Style/Documentation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/HashEachMethods:
|
46
|
+
Enabled: true
|
47
|
+
|
48
|
+
Style/HashTransformKeys:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
Style/HashTransformValues:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Style/Lambda:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/SymbolArray:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
# Use a trailing comma to keep diffs clean when elements are inserted or removed
|
61
|
+
Style/TrailingCommaInArguments:
|
62
|
+
EnforcedStyleForMultiline: no_comma
|
63
|
+
|
64
|
+
Style/TrailingCommaInArrayLiteral:
|
65
|
+
EnforcedStyleForMultiline: comma
|
66
|
+
|
67
|
+
Style/TrailingCommaInHashLiteral:
|
68
|
+
EnforcedStyleForMultiline: comma
|
69
|
+
|
70
|
+
Style/WordArray:
|
71
|
+
Enabled: false
|
data/API.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# WC
|
2
|
+
|
3
|
+
## CountTracker
|
4
|
+
|
5
|
+
### Description
|
6
|
+
Allows to track how many times an item is called.
|
7
|
+
|
8
|
+
### Usage
|
9
|
+
|
10
|
+
#### Sample
|
11
|
+
```
|
12
|
+
tracker = WC::CountTracker.new
|
13
|
+
tracker.increase(key)
|
14
|
+
tracker.count(key) # => 1
|
15
|
+
```
|
16
|
+
|
17
|
+
#### Chaining
|
18
|
+
```
|
19
|
+
tracker = WC::CountTracker.new
|
20
|
+
tracker.increase(key).increase(key)
|
21
|
+
tracker.count(key) # => 2
|
22
|
+
```
|
23
|
+
|
24
|
+
#### Get above
|
25
|
+
```
|
26
|
+
tracker = WC::CountTracker.new(
|
27
|
+
{
|
28
|
+
one: 1,
|
29
|
+
two: 2,
|
30
|
+
three: 3,
|
31
|
+
other_three: 3,
|
32
|
+
}
|
33
|
+
)
|
34
|
+
tracker.increase(key).increase(key)
|
35
|
+
tracker.above(2) # => { three: 3, other_three: 3 }
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Get above (keys)
|
39
|
+
```
|
40
|
+
tracker = WC::CountTracker.new(
|
41
|
+
{
|
42
|
+
one: 1,
|
43
|
+
two: 2,
|
44
|
+
three: 3,
|
45
|
+
other_three: 3,
|
46
|
+
}
|
47
|
+
)
|
48
|
+
tracker.increase(key).increase(key)
|
49
|
+
tracker.above(2).keys # => [:three, :other_three]
|
50
|
+
```
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
5
|
+
|
6
|
+
## [Unreleased]
|
7
|
+
|
8
|
+
## [0.1.0] - 2023-03-13
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Include `class_helpers`, `class_registers` & `count_tracker` from `cognito` project.
|
13
|
+
- Convert any rails dependency to native ruby.
|
14
|
+
|
15
|
+
[unreleased]: https://github.com/WorkCompass/wc-essentials/compare/0.1.0...HEAD
|
16
|
+
[0.1.0]: https://github.com/WorkCompass/wc-essentials/releases/tag/0.1.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wc-essentials (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
debase (0.2.4.1)
|
11
|
+
debase-ruby_core_source (>= 0.10.2)
|
12
|
+
debase-ruby_core_source (0.10.17)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
docile (1.3.5)
|
15
|
+
jaro_winkler (1.5.4)
|
16
|
+
json (2.6.2)
|
17
|
+
parallel (1.19.2)
|
18
|
+
parser (3.1.3.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
json
|
21
|
+
rainbow (3.1.1)
|
22
|
+
rake (13.0.6)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.12.0)
|
25
|
+
rspec-core (~> 3.12.0)
|
26
|
+
rspec-expectations (~> 3.12.0)
|
27
|
+
rspec-mocks (~> 3.12.0)
|
28
|
+
rspec-core (3.12.0)
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-expectations (3.12.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-mocks (3.12.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-support (3.12.0)
|
37
|
+
rubocop (0.81.0)
|
38
|
+
jaro_winkler (~> 1.5.1)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 2.7.0.1)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
rexml
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
45
|
+
rubocop-rspec (1.38.1)
|
46
|
+
rubocop (>= 0.68.1)
|
47
|
+
ruby-debug-ide (0.7.3)
|
48
|
+
rake (>= 0.8.1)
|
49
|
+
ruby-progressbar (1.11.0)
|
50
|
+
simplecov (0.17.1)
|
51
|
+
docile (~> 1.1)
|
52
|
+
json (>= 1.8, < 3)
|
53
|
+
simplecov-html (~> 0.10.0)
|
54
|
+
simplecov-html (0.10.2)
|
55
|
+
unicode-display_width (1.8.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 1.17)
|
62
|
+
debase (~> 0.2)
|
63
|
+
rake (~> 13.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
rubocop (~> 0.81)
|
66
|
+
rubocop-rspec (~> 1.38)
|
67
|
+
ruby-debug-ide (~> 0.7)
|
68
|
+
simplecov (~> 0.17)
|
69
|
+
wc-essentials!
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.17.3
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 WorkCompass
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# WC::Essentials
|
2
|
+
|
3
|
+
Gem to provide essential and commonly used helpers to all WorkCompass projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'wc-essentials'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install wc-essentials
|
20
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'wc/essentials'
|
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,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WC
|
4
|
+
module Essentials
|
5
|
+
# Helpers for classes
|
6
|
+
module ClassHelpers
|
7
|
+
# Get the class variable name
|
8
|
+
# @param {class} klass
|
9
|
+
# @param {symbol} name
|
10
|
+
# @returns {string}
|
11
|
+
def self.klass_var_name(klass, name)
|
12
|
+
"@@#{
|
13
|
+
klass.name.split('::')
|
14
|
+
.join('_')
|
15
|
+
.downcase
|
16
|
+
}_#{name}"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Assign class variable and also merge parent
|
20
|
+
# class variable.
|
21
|
+
# Usefull if required to have class variable
|
22
|
+
# only bind to the class in the case of inheritence
|
23
|
+
# @param {class} klass
|
24
|
+
# @param {symbol} name
|
25
|
+
# @param {any} value
|
26
|
+
def self.assign_class_variable(klass, name, value)
|
27
|
+
klass.ancestors.each do |ancestor|
|
28
|
+
value = concat_var(ancestor, name, value)
|
29
|
+
end
|
30
|
+
|
31
|
+
k_var_name = klass_var_name(klass, name)
|
32
|
+
klass.class_variable_set(k_var_name, value)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Concat values from value provided
|
36
|
+
# with value assigned to the class variable
|
37
|
+
# @param {class} klass
|
38
|
+
# @param {symbol} name
|
39
|
+
# @param {any} value
|
40
|
+
# @returns {any} The value merged
|
41
|
+
def self.concat_var(klass, name, value)
|
42
|
+
var_name = klass_var_name(klass, name)
|
43
|
+
existing = var_value(
|
44
|
+
klass,
|
45
|
+
var_name,
|
46
|
+
value.is_a?(Array) ? [] : {}
|
47
|
+
)
|
48
|
+
|
49
|
+
(value.is_a?(Array) ? (existing + value) : value.merge(existing))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return the value of class variable
|
53
|
+
# @param {class} klass
|
54
|
+
# @param {symbol} name
|
55
|
+
# @param {any} default
|
56
|
+
# @returns {any}
|
57
|
+
# - default value if nothing found
|
58
|
+
def self.var_value(klass, name, default = [])
|
59
|
+
return default unless defined?(klass.class_variable_get(name))
|
60
|
+
|
61
|
+
klass.class_variable_get(name)
|
62
|
+
rescue StandardError
|
63
|
+
default
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './class_helpers'
|
4
|
+
|
5
|
+
module WC
|
6
|
+
module Essentials
|
7
|
+
# Helpers for registration
|
8
|
+
module ClassRegisters
|
9
|
+
extend self
|
10
|
+
|
11
|
+
######################################
|
12
|
+
# Class Methods
|
13
|
+
######################################
|
14
|
+
|
15
|
+
# Class variable getter
|
16
|
+
# @param {symbol} name
|
17
|
+
# @param {any} default
|
18
|
+
# @returns {any}
|
19
|
+
def var(name, default = [])
|
20
|
+
var_name = WC::Essentials::ClassHelpers.klass_var_name(self, name)
|
21
|
+
class_variable_get(var_name)
|
22
|
+
rescue StandardError
|
23
|
+
default
|
24
|
+
end
|
25
|
+
|
26
|
+
# Register CSV fields and if required
|
27
|
+
# @param {Hash}
|
28
|
+
def fields(fields = {})
|
29
|
+
WC::Essentials::ClassHelpers.assign_class_variable(self, :fields, fields)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Register CSV fields that represent identities
|
33
|
+
# @param {Hash} identities Key/value where value represent boolean allow duplication
|
34
|
+
def identities(identities = {})
|
35
|
+
WC::Essentials::ClassHelpers.assign_class_variable(self, :identities, identities)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Register validators to be run for validation
|
39
|
+
# @params {symbol}
|
40
|
+
def validators(*validators)
|
41
|
+
WC::Essentials::ClassHelpers.assign_class_variable(self, :validators, validators)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Register collectors to be run once main
|
45
|
+
# validation. Registered collectors here
|
46
|
+
# will not run if halted early
|
47
|
+
# @params {symbol}
|
48
|
+
def after_validation(*collectors)
|
49
|
+
WC::Essentials::ClassHelpers.assign_class_variable(self, :collectors, collectors)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WC
|
4
|
+
module Essentials
|
5
|
+
# Tracker for number
|
6
|
+
# of a key
|
7
|
+
class CountTracker
|
8
|
+
def initialize(data = {})
|
9
|
+
@tracking = data
|
10
|
+
end
|
11
|
+
|
12
|
+
# Increase the count for the
|
13
|
+
# key provided
|
14
|
+
# @param {any} key
|
15
|
+
# @returns self
|
16
|
+
def increase(key)
|
17
|
+
@tracking ||= {}
|
18
|
+
|
19
|
+
@tracking[key] = 0 unless @tracking.key?(key)
|
20
|
+
@tracking[key] += 1
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return count for specified key
|
25
|
+
# @param {any} key
|
26
|
+
# @returns {int}
|
27
|
+
def count(key)
|
28
|
+
return unless @tracking.key?(key)
|
29
|
+
|
30
|
+
@tracking[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return keys for
|
34
|
+
# item the number provider
|
35
|
+
# equivalent to greater than
|
36
|
+
# @param {int} min
|
37
|
+
# @returns {hash}
|
38
|
+
def above(min)
|
39
|
+
@tracking.select { |_key, total| total > min }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'wc/essentials/version'
|
4
|
+
require 'wc/essentials/class_helpers'
|
5
|
+
require 'wc/essentials/class_registers'
|
6
|
+
require 'wc/essentials/count_tracker'
|
7
|
+
|
8
|
+
module WC
|
9
|
+
module Essentials
|
10
|
+
class << self
|
11
|
+
# Provide developer to setup
|
12
|
+
# def configure
|
13
|
+
# yield self
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'wc/essentials/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'wc-essentials'
|
9
|
+
spec.version = WC::Essentials::VERSION
|
10
|
+
spec.authors = ['WorkCompass Dev Team']
|
11
|
+
spec.email = ['dev@workcompass.com']
|
12
|
+
|
13
|
+
spec.summary = 'Reusable helpers for all WorkCompass web applications.'
|
14
|
+
spec.description = 'Gem to provide essential and commonly used helpers to all WorkCompass projects.'
|
15
|
+
spec.homepage = 'https://workcompass.com'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes
|
19
|
+
# either set the 'allowed_push_host' to allow pushing to a
|
20
|
+
# single host or delete this section to allow pushing to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata['homepage_uri'] = spec.homepage
|
23
|
+
# spec.metadata['source_code_uri'] = 'https://github.com/WorkCompass/wc-essentials'
|
24
|
+
# else
|
25
|
+
# raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
# 'public gem pushes.'
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have
|
31
|
+
# been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
34
|
+
f.match(%r{^(test|spec|features)/})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
spec.bindir = 'exe'
|
38
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
39
|
+
spec.require_paths = ['lib']
|
40
|
+
|
41
|
+
# Dev dependencies
|
42
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
43
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
44
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
+
|
46
|
+
# Quality control
|
47
|
+
spec.add_development_dependency 'rubocop', '~> 0.81'
|
48
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.38'
|
49
|
+
spec.add_development_dependency 'simplecov', '~> 0.17'
|
50
|
+
|
51
|
+
# Debugger for IDE
|
52
|
+
spec.add_development_dependency 'debase', '~> 0.2'
|
53
|
+
spec.add_development_dependency 'ruby-debug-ide', '~> 0.7'
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wc-essentials
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- WorkCompass Dev Team
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.81'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.81'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.38'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.38'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.17'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.17'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: debase
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ruby-debug-ide
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.7'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.7'
|
125
|
+
description: Gem to provide essential and commonly used helpers to all WorkCompass
|
126
|
+
projects.
|
127
|
+
email:
|
128
|
+
- dev@workcompass.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".devcontainer/Dockerfile"
|
134
|
+
- ".devcontainer/devcontainer.json"
|
135
|
+
- ".devcontainer/postCreateCommands.sh"
|
136
|
+
- ".github/workflows/coverage.yml"
|
137
|
+
- ".github/workflows/publish-gem.yml"
|
138
|
+
- ".github/workflows/test-base.yml"
|
139
|
+
- ".github/workflows/test-essentials.yml"
|
140
|
+
- ".gitignore"
|
141
|
+
- ".rspec"
|
142
|
+
- ".rubocop.yml"
|
143
|
+
- API.md
|
144
|
+
- CHANGELOG.md
|
145
|
+
- Gemfile
|
146
|
+
- Gemfile.lock
|
147
|
+
- LICENSE.md
|
148
|
+
- README.md
|
149
|
+
- Rakefile
|
150
|
+
- bin/console
|
151
|
+
- bin/setup
|
152
|
+
- lib/wc/essentials.rb
|
153
|
+
- lib/wc/essentials/class_helpers.rb
|
154
|
+
- lib/wc/essentials/class_registers.rb
|
155
|
+
- lib/wc/essentials/count_tracker.rb
|
156
|
+
- lib/wc/essentials/version.rb
|
157
|
+
- wc-essentials.gemspec
|
158
|
+
homepage: https://workcompass.com
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata: {}
|
162
|
+
post_install_message:
|
163
|
+
rdoc_options: []
|
164
|
+
require_paths:
|
165
|
+
- lib
|
166
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
requirements: []
|
177
|
+
rubygems_version: 3.3.5
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Reusable helpers for all WorkCompass web applications.
|
181
|
+
test_files: []
|