environment_helpers 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/quality.yml +29 -0
- data/.github/workflows/rspec.yml +4 -2
- data/.github/workflows/type_check.yml +18 -0
- data/.mdl_rules.rb +2 -0
- data/.mdlrc +2 -0
- data/.quiet_quality.ci-cd.yml +7 -0
- data/.quiet_quality.yml +7 -0
- data/CHANGELOG.md +42 -0
- data/Gemfile +4 -0
- data/README.md +68 -40
- data/Steepfile +17 -0
- data/environment_helpers.gemspec +4 -1
- data/lib/environment_helpers/boolean_helpers.rb +16 -4
- data/lib/environment_helpers/enumerable_helpers.rb +45 -0
- data/lib/environment_helpers/range_helpers.rb +1 -1
- data/lib/environment_helpers/string_helpers.rb +1 -1
- data/lib/environment_helpers/version.rb +1 -1
- data/lib/environment_helpers.rb +10 -7
- data/sig/environment_helpers.rbs +96 -0
- metadata +56 -5
- data/.github/workflows/lint.yml +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e1df5aabc663c1ed5969c56db3d1be35f6b329272718ce174b30260f4c2f1e8
|
4
|
+
data.tar.gz: 855f2cf510c568464310ef1bc30fb6115a6dff653618f25472a452fcf901cb77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dcccd3be2e778d76ce595521efc58204b680acfbe3328c86e357946574c338e323ee7a4e479e39d768f97a67fb6ecb7bb2c7aad7c68db7ed2d6f30bd761f299
|
7
|
+
data.tar.gz: 6a9bccc3864329bf295f59c268d64bed2078d072f9eed08ce2ff3063ead716f2e3e5a14b333f710b01b6092ec3be595bb71e74548c83515f230dfb9306e51bd7
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Quiet Quality
|
2
|
+
|
3
|
+
on: push
|
4
|
+
permissions: write-all
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
check:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v4
|
11
|
+
with:
|
12
|
+
fetch-depth: 0
|
13
|
+
|
14
|
+
- name: Show the merge-base
|
15
|
+
run: git merge-base origin/main ${{ github.sha }}
|
16
|
+
if: github.branch != 'main'
|
17
|
+
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 3.2
|
22
|
+
|
23
|
+
- name: Install gems
|
24
|
+
run: bundle install --jobs 4 --retry 3
|
25
|
+
|
26
|
+
- name: Run QuietQuality
|
27
|
+
run: |
|
28
|
+
gem install quiet_quality standard rubocop
|
29
|
+
qq -C .quiet_quality.ci-cd.yml
|
data/.github/workflows/rspec.yml
CHANGED
@@ -8,10 +8,12 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
ruby-version: ['2.
|
11
|
+
ruby-version: ['2.7', '3.0', '3.1', '3.2', 'head']
|
12
|
+
env:
|
13
|
+
NO_STEEP: "Because we need to test on versions that are older than steep supports"
|
12
14
|
|
13
15
|
steps:
|
14
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
15
17
|
|
16
18
|
- name: Set up ruby
|
17
19
|
uses: ruby/setup-ruby@v1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Steep Type Checking
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
check:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v4
|
10
|
+
|
11
|
+
- name: Set up ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 3.3
|
15
|
+
bundler-cache: true
|
16
|
+
|
17
|
+
- name: Run Steep
|
18
|
+
run: bundle exec steep check
|
data/.mdl_rules.rb
ADDED
data/.mdlrc
ADDED
data/.quiet_quality.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Release 1.5.0
|
4
|
+
|
5
|
+
* Add rbs/steep, and enforce types in CI (.rbs file is exported as part
|
6
|
+
of the gem) (#28, resolves #21)
|
7
|
+
* Support env-based customization of the truthy/falsey strings used by
|
8
|
+
`ENV.boolean` (#29, resolves #27)
|
9
|
+
* Update github workflows to use checkout@v4 (which should have no real
|
10
|
+
impact on us, aside from staying current). (#30)
|
11
|
+
* Update README to explain `ENV.array`
|
12
|
+
|
13
|
+
## Release 1.4.0
|
14
|
+
|
15
|
+
* Drop support for ruby 2.6
|
16
|
+
* Setup `quiet_quality` through the gemspec
|
17
|
+
* Setup `markdownlint` and comply with its rules (#25)
|
18
|
+
* Setup `rspec-cover_it` to enforce test-coverage (#24)
|
19
|
+
|
20
|
+
## Release 1.3.0
|
21
|
+
|
22
|
+
* Support `ENV.date_time` (#19, resolves #6)
|
23
|
+
|
24
|
+
## Release 1.2.1
|
25
|
+
|
26
|
+
* Require `set` before loading the gem, since we support rubies before 3.2 (#18)
|
27
|
+
|
28
|
+
## Release 1.2.0
|
29
|
+
|
30
|
+
* Support `ENV.file_path` returning Pathname objects (#16, resolves #13)
|
31
|
+
|
32
|
+
## Release 1.1.0
|
33
|
+
|
34
|
+
* Support `ENV.integer_range` (#15, resolves #5)
|
35
|
+
|
36
|
+
## Release 1.0.1
|
37
|
+
|
38
|
+
* Specify dependencies more tightly (#14)
|
39
|
+
|
40
|
+
## Release 1.0.0
|
41
|
+
|
42
|
+
(Initial release)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,40 @@
|
|
1
1
|
# EnvironmentHelpers
|
2
|
-
This gem adds a set of convenience helpers to `ENV`, allowing you to access environment variables
|
3
|
-
in a more structures and consistent way. Have you seen any line like these?
|
4
2
|
|
5
|
-
|
3
|
+
This gem adds a set of convenience helpers to `ENV`, allowing you to access
|
4
|
+
environment variables in a more structures and consistent way. Have you seen
|
5
|
+
any line like these?
|
6
|
+
|
7
|
+
```ruby
|
6
8
|
enable_bar = ENV.fetch("ENABLE_BAR", "false") == "true"
|
7
9
|
foo_count = ENV.fetch("FOO_TOTAL", "100").to_i
|
8
10
|
```
|
9
11
|
|
10
|
-
This works okay! And it's not really that complicated, working out what's going
|
11
|
-
that difficult. How about this?
|
12
|
+
This works okay! And it's not really that complicated, working out what's going
|
13
|
+
on here isn't that difficult. How about this?
|
12
14
|
|
13
|
-
```
|
15
|
+
```ruby
|
14
16
|
enable_foo = ENV.fetch("ENABLE_FOO", "false") != "true"
|
15
17
|
```
|
16
18
|
|
17
|
-
That.. looks very similar, but means the opposite thing. Also not that tricky.
|
18
|
-
to _wish_ for a tool like EnvironmentHelpers until these
|
19
|
-
But.. if you're using a 12-factor
|
20
|
-
|
19
|
+
That.. looks very similar, but means the opposite thing. Also not that tricky.
|
20
|
+
You don't start to _wish_ for a tool like EnvironmentHelpers until these
|
21
|
+
constructions get complex and compounded. But.. if you're using a 12-factor
|
22
|
+
style of configuration, you probably have these ENV-fetches sprinkled
|
23
|
+
_everywhere_, so making them moderately clearer or simpler can pay off fairly
|
24
|
+
quickly.
|
21
25
|
|
22
26
|
## Installation
|
23
27
|
|
24
|
-
```
|
28
|
+
```ruby
|
25
29
|
gem "environment_helper"
|
26
30
|
```
|
27
31
|
|
28
|
-
There's not much to it - add the gem to your gemfile and when it's loaded it'll
|
29
|
-
methods onto `ENV` for your use.
|
32
|
+
There's not much to it - add the gem to your gemfile and when it's loaded it'll
|
33
|
+
add some extra methods onto `ENV` for your use.
|
30
34
|
|
31
35
|
## Usage
|
32
36
|
|
33
|
-
```
|
37
|
+
```ruby
|
34
38
|
ENV.string("APP_NAME", default: "local")
|
35
39
|
ENV.symbol("BUSINESS_DOMAIN", default: :engineering, required: true)
|
36
40
|
ENV.boolean("ENABLE_FEATURE_FOO", default: false)
|
@@ -39,34 +43,58 @@ ENV.integer("MAX_THREAD_COUNT", default: 5)
|
|
39
43
|
ENV.file_path("FILE_PATH", default: "/some/path", required: true)
|
40
44
|
ENV.date("SCHEDULED_DATE", required: true, format: "%Y-%m-%d")
|
41
45
|
ENV.date_time("RUN_AT", required: true, default: DateTime.now)
|
46
|
+
ENV.array("QUEUE_NAMES", of: :strings, required: false, default: ["high", "low"])
|
42
47
|
```
|
43
48
|
|
44
|
-
Each of the supplied methods takes a positional parameter for the name of the
|
45
|
-
and then two optional named parameters `default` and
|
46
|
-
both, but nothing stops you from doing
|
47
|
-
|
48
|
-
|
49
|
+
Each of the supplied methods takes a positional parameter for the name of the
|
50
|
+
environment variable, and then two optional named parameters `default` and
|
51
|
+
`required` (there's no point in supplying both, but nothing stops you from doing
|
52
|
+
so). The `default` value is the value used if the variable isn't present in the
|
53
|
+
environment. If `required` is set to a truthy value, then if the variable isn't
|
54
|
+
present in the environment, an `EnvironmentHelpers::MissingVariableError` is
|
55
|
+
raised.
|
49
56
|
|
50
57
|
The available methods added to `ENV`:
|
51
58
|
|
52
|
-
* `string` - environment values are already strings, so this is the simplest of
|
53
|
-
|
54
|
-
* `
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
* `
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
* `string` - environment values are already strings, so this is the simplest of
|
60
|
+
the methods.
|
61
|
+
* `symbol` - produces a symbol, and enforces that the default value is either
|
62
|
+
`nil` or a Symbol.
|
63
|
+
* `boolean` - produces `nil`, `true`, or `false` (and only allows those as
|
64
|
+
defaults). Supports.. a fair variety of strings to map onto those boolean
|
65
|
+
value, though you should probably just use "true" and "false" really. If you
|
66
|
+
specify `required: true` and get a value like "maybe?", it'll raise an
|
67
|
+
`EnvironmentHelpers::InvalidBooleanText` exception.
|
68
|
+
* `integer_range` - produces an integer Range object. It accepts `N-N`, `N..N`,
|
69
|
+
or `N...N`, (the latter means 'excluding the upper bound, as in ruby).
|
70
|
+
* `integer` - produces an integer from the environment variable, by calling
|
71
|
+
`to_i` on it (if it's present). Note that this means that providing a value
|
72
|
+
like "hello" means you'll get `0`, since that's what ruby does when you call
|
73
|
+
`"hello".to_i`.
|
74
|
+
* `file_path` - produces a `Pathname` initialized with the path specified by the
|
75
|
+
environment variable.
|
76
|
+
* `date` - produces a `Date` object, using `Date.strptime`. The default format
|
77
|
+
string is `%Y-%m-%d`, which would parse a date like `2023-12-25`. It will
|
78
|
+
handle invalid values (or format strings) like the variable not being present,
|
79
|
+
though if it's specified as `required`, you will see a different exception in
|
80
|
+
each case.
|
81
|
+
* `date_time` - produces a `DateTime` object, using either `DateTime.strptime`
|
82
|
+
or `DateTime.iso8601`. The default format is `:iso8601`, and `:unix` is also
|
83
|
+
an allowed 'format'. But if it is supplied as a _string_, it will be handled
|
84
|
+
as a strptime format string (the `:unix` format is equivalent to the format
|
85
|
+
string `"%s"`). It handles invalid or unparseable values like `ENV.date` does,
|
86
|
+
in that they are treated as if not supplied.
|
87
|
+
* `array` - produces an array of strings, symbols, or integers, depending on the
|
88
|
+
value of the `of` parameter. You can specify the delimiter using a `delimiter`
|
89
|
+
parameter (it defaults to a comma).
|
90
|
+
|
91
|
+
## Configuration
|
92
|
+
|
93
|
+
If you want to specify your own list of truthy/falsey strings, you can do that
|
94
|
+
by setting either or both of these environment variables, supplying comma-
|
95
|
+
separated (whitespace-free) strings:
|
96
|
+
|
97
|
+
* `ENVIRONMENT_HELPERS_TRUTHY_STRINGS` - the default value used is
|
98
|
+
`true,yes,on,enabled,enable,allow,t,y,1,ok,okay`
|
99
|
+
* `ENVIRONMENT_HELPERS_FALSEY_STRINGS` - the default value used is
|
100
|
+
`false,no,off,disabled,disable,deny,f,n,0,nope`
|
data/Steepfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
D = Steep::Diagnostic
|
2
|
+
|
3
|
+
target :lib do
|
4
|
+
signature "sig"
|
5
|
+
check "lib"
|
6
|
+
configure_code_diagnostics(D::Ruby.default)
|
7
|
+
library "pathname"
|
8
|
+
library "date"
|
9
|
+
end
|
10
|
+
|
11
|
+
target :test do
|
12
|
+
signature "sig"
|
13
|
+
check "test"
|
14
|
+
configure_code_diagnostics(D::Ruby.default)
|
15
|
+
library "pathname"
|
16
|
+
library "date"
|
17
|
+
end
|
data/environment_helpers.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
DESC
|
14
14
|
spec.homepage = "https://github.com/nevinera/environment_helpers"
|
15
15
|
spec.license = "MIT"
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -30,7 +30,10 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.10"
|
32
32
|
spec.add_development_dependency "simplecov", "~> 0.22.0"
|
33
|
+
spec.add_development_dependency "rspec-cover_it", "~> 0.1.0"
|
33
34
|
spec.add_development_dependency "pry", "~> 0.14"
|
34
35
|
spec.add_development_dependency "standard", "~> 1.28"
|
35
36
|
spec.add_development_dependency "rubocop", "~> 1.50"
|
37
|
+
spec.add_development_dependency "quiet_quality", "~> 1.3.0"
|
38
|
+
spec.add_development_dependency "mdl", "~> 0.12"
|
36
39
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module EnvironmentHelpers
|
2
2
|
module BooleanHelpers
|
3
|
-
TRUTHY_STRINGS = %w[true yes on enabled enable allow t y 1 ok okay].to_set
|
4
|
-
FALSEY_STRINGS = %w[false no off disabled disable deny f n 0 nope].to_set
|
5
3
|
BOOLEAN_VALUES = [true, false, nil].to_set
|
6
4
|
|
7
5
|
def boolean(name, default: nil, required: false)
|
@@ -19,12 +17,26 @@ module EnvironmentHelpers
|
|
19
17
|
|
20
18
|
def truthy_text?(text)
|
21
19
|
return false if text.nil?
|
22
|
-
|
20
|
+
truthy_strings.include?(text.strip.downcase)
|
23
21
|
end
|
24
22
|
|
25
23
|
def falsey_text?(text)
|
26
24
|
return false if text.nil?
|
27
|
-
|
25
|
+
falsey_strings.include?(text.strip.downcase)
|
26
|
+
end
|
27
|
+
|
28
|
+
def truthy_strings
|
29
|
+
@_truthy_strings ||=
|
30
|
+
ENV.fetch("ENVIRONMENT_HELPERS_TRUTHY_STRINGS", "true,yes,on,enabled,enable,allow,t,y,1,ok,okay")
|
31
|
+
.split(",")
|
32
|
+
.to_set
|
33
|
+
end
|
34
|
+
|
35
|
+
def falsey_strings
|
36
|
+
@_falsey_strings ||=
|
37
|
+
ENV.fetch("ENVIRONMENT_HELPERS_FALSEY_STRINGS", "false,no,off,disabled,disable,deny,f,n,0,nope")
|
38
|
+
.split(",")
|
39
|
+
.to_set
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EnvironmentHelpers
|
2
|
+
module EnumerableHelpers
|
3
|
+
VALID_TYPES = %i[strings symbols integers]
|
4
|
+
|
5
|
+
TYPE_HANDLERS = {
|
6
|
+
integers: :to_i,
|
7
|
+
strings: :to_s,
|
8
|
+
symbols: :to_sym
|
9
|
+
}
|
10
|
+
|
11
|
+
TYPE_MAP = {
|
12
|
+
integers: Integer,
|
13
|
+
strings: String,
|
14
|
+
symbols: Symbol
|
15
|
+
}
|
16
|
+
|
17
|
+
def array(key, of: :strings, delimiter: ",", default: nil, required: false)
|
18
|
+
check_default_type(:array, default, Array)
|
19
|
+
check_valid_data_type!(of)
|
20
|
+
check_default_data_types!(default, of)
|
21
|
+
|
22
|
+
values = fetch_value(key, required: required)
|
23
|
+
return default if values.nil?
|
24
|
+
|
25
|
+
values.split(delimiter).map { |value| value.send(TYPE_HANDLERS[of]) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def check_valid_data_type!(type)
|
31
|
+
unless VALID_TYPES.include?(type)
|
32
|
+
fail(InvalidType, "Valid types: #{VALID_TYPES.join(", ")}. Got: #{type}.")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_default_data_types!(default, type)
|
37
|
+
return if default.nil?
|
38
|
+
invalid = Array(default).reject { |val| val.is_a? TYPE_MAP[type] }
|
39
|
+
|
40
|
+
unless invalid.empty?
|
41
|
+
fail(BadDefault, "Default array contains values not of type `#{type}': #{invalid.join(", ")}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -6,7 +6,7 @@ module EnvironmentHelpers
|
|
6
6
|
check_range_endpoint(:integer_range, default.end) if default
|
7
7
|
|
8
8
|
text = fetch_value(name, required: required)
|
9
|
-
range = parse_range_from(text)
|
9
|
+
range = text ? parse_range_from(text) : nil
|
10
10
|
return range if range
|
11
11
|
return default unless required
|
12
12
|
fail(InvalidRangeText, "Required Integer Range environment variable #{name} had inappropriate content '#{text}'")
|
@@ -6,7 +6,7 @@ module EnvironmentHelpers
|
|
6
6
|
|
7
7
|
def symbol(name, default: nil, required: false)
|
8
8
|
check_default_type(:symbol, default, Symbol)
|
9
|
-
string(name, default: default, required: required)&.to_sym
|
9
|
+
string(name, default: default&.to_s, required: required)&.to_sym
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/environment_helpers.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
# And we're compatible back to 2.6
|
3
3
|
require "set" # rubocop:disable Lint/RedundantRequireStatement
|
4
4
|
|
5
|
-
require_relative "
|
6
|
-
require_relative "
|
7
|
-
require_relative "
|
8
|
-
require_relative "
|
9
|
-
require_relative "
|
10
|
-
require_relative "
|
11
|
-
require_relative "
|
5
|
+
require_relative "environment_helpers/access_helpers"
|
6
|
+
require_relative "environment_helpers/string_helpers"
|
7
|
+
require_relative "environment_helpers/boolean_helpers"
|
8
|
+
require_relative "environment_helpers/range_helpers"
|
9
|
+
require_relative "environment_helpers/numeric_helpers"
|
10
|
+
require_relative "environment_helpers/file_helpers"
|
11
|
+
require_relative "environment_helpers/datetime_helpers"
|
12
|
+
require_relative "environment_helpers/enumerable_helpers"
|
12
13
|
|
13
14
|
module EnvironmentHelpers
|
14
15
|
Error = Class.new(::StandardError)
|
@@ -16,6 +17,7 @@ module EnvironmentHelpers
|
|
16
17
|
BadDefault = Class.new(Error)
|
17
18
|
BadFormat = Class.new(Error)
|
18
19
|
|
20
|
+
InvalidType = Class.new(Error)
|
19
21
|
InvalidValue = Class.new(Error)
|
20
22
|
InvalidBooleanText = Class.new(InvalidValue)
|
21
23
|
InvalidRangeText = Class.new(InvalidValue)
|
@@ -30,6 +32,7 @@ module EnvironmentHelpers
|
|
30
32
|
include NumericHelpers
|
31
33
|
include FileHelpers
|
32
34
|
include DatetimeHelpers
|
35
|
+
include EnumerableHelpers
|
33
36
|
end
|
34
37
|
|
35
38
|
ENV.extend(EnvironmentHelpers)
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module EnvironmentHelpers
|
2
|
+
VERSION: String
|
3
|
+
|
4
|
+
class Error < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class MissingVariableError < Error
|
8
|
+
end
|
9
|
+
|
10
|
+
class BadDefault < Error
|
11
|
+
end
|
12
|
+
|
13
|
+
class BadFormat < Error
|
14
|
+
end
|
15
|
+
|
16
|
+
class InvalidType < Error
|
17
|
+
end
|
18
|
+
|
19
|
+
class InvalidValue < Error
|
20
|
+
end
|
21
|
+
|
22
|
+
class InvalidBooleanText < InvalidValue
|
23
|
+
end
|
24
|
+
|
25
|
+
class InvalidRangeText < InvalidValue
|
26
|
+
end
|
27
|
+
|
28
|
+
class InvalidIntegerText < InvalidValue
|
29
|
+
end
|
30
|
+
|
31
|
+
class InvalidDateText < InvalidValue
|
32
|
+
end
|
33
|
+
|
34
|
+
class InvalidDateTimeText < InvalidValue
|
35
|
+
end
|
36
|
+
|
37
|
+
module AccessHelpers
|
38
|
+
# (Actually provided by ENV, which these are all extended onto)
|
39
|
+
def fetch: (String name) -> String?
|
40
|
+
| (String name, String? default) -> String?
|
41
|
+
|
42
|
+
private def fetch_value: (String name, required: bool) -> String?
|
43
|
+
private def check_default_type: (String | Symbol context, untyped value, *Class types) -> void
|
44
|
+
private def check_default_value: (String | Symbol context, untyped value, allow: Enumerable[untyped]) -> void
|
45
|
+
end
|
46
|
+
|
47
|
+
module FileHelpers : AccessHelpers
|
48
|
+
def file_path: (String name, default: String?, required: bool) -> Pathname?
|
49
|
+
end
|
50
|
+
|
51
|
+
module DatetimeHelpers : AccessHelpers
|
52
|
+
type date_time_result = DateTime? | Time?
|
53
|
+
def date: (String name, format: String, default: Date?, required: bool) -> Date?
|
54
|
+
def date_time: (String name, format: String | Symbol, default: date_time_result, required: bool) -> date_time_result
|
55
|
+
private def parse_date_from: (String? text, format: String) -> Date?
|
56
|
+
private def parse_date_time_from: (String? text, format: String | Symbol) -> DateTime?
|
57
|
+
private def iso8601_date_time: (String) -> DateTime?
|
58
|
+
private def unix_date_time: (String) -> DateTime?
|
59
|
+
private def strptime_date_time: (String, format: String) -> DateTime?
|
60
|
+
end
|
61
|
+
|
62
|
+
module NumericHelpers : AccessHelpers
|
63
|
+
def integer: (String name, default: Integer?, required: bool) -> Integer?
|
64
|
+
end
|
65
|
+
|
66
|
+
module RangeHelpers : AccessHelpers
|
67
|
+
def integer_range: (String name, default: Range[Integer]?, required: bool) -> Range[Integer]?
|
68
|
+
private def check_range_endpoint: (String | Symbol context, untyped value) -> void
|
69
|
+
private def parse_range_bound_from: (String?) -> Integer?
|
70
|
+
private def parse_range_from: (String) -> Range[Integer]?
|
71
|
+
end
|
72
|
+
|
73
|
+
module BooleanHelpers : AccessHelpers
|
74
|
+
BOOLEAN_VALUES: Set[bool]
|
75
|
+
def boolean: (String name, default: bool?, required: bool) -> boolish
|
76
|
+
private def truthy_text?: (String?) -> boolish
|
77
|
+
private def falsey_text?: (String?) -> boolish
|
78
|
+
private def truthy_strings: () -> Set[String]
|
79
|
+
private def falsey_strings: () -> Set[String]
|
80
|
+
end
|
81
|
+
|
82
|
+
module EnumerableHelpers : AccessHelpers
|
83
|
+
VALID_TYPES: Array[Symbol]
|
84
|
+
TYPE_HANDLERS: Hash[Symbol, Symbol]
|
85
|
+
TYPE_MAP: Hash[Symbol, Class]
|
86
|
+
type arrayable = Integer | String | Symbol
|
87
|
+
def array: (String key, of: Symbol, delimiter: String, default: Array[arrayable]?, required: bool) -> Array[arrayable]?
|
88
|
+
private def check_valid_data_type!: (Symbol) -> void
|
89
|
+
private def check_default_data_types!: (Array[arrayable]?, Symbol) -> void
|
90
|
+
end
|
91
|
+
|
92
|
+
module StringHelpers : AccessHelpers
|
93
|
+
def string: (String name, default: String?, required: bool) -> String?
|
94
|
+
def symbol: (String name, default: Symbol?, required: bool) -> Symbol?
|
95
|
+
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: environment_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.22.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-cover_it
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,34 @@ dependencies:
|
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '1.50'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: quiet_quality
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mdl
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.12'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.12'
|
83
125
|
description: |
|
84
126
|
Convenience helpers for more simply accessing data passed to applications through the
|
85
127
|
environment that may have types and/or defaults
|
@@ -89,24 +131,33 @@ executables: []
|
|
89
131
|
extensions: []
|
90
132
|
extra_rdoc_files: []
|
91
133
|
files:
|
92
|
-
- ".github/workflows/
|
134
|
+
- ".github/workflows/quality.yml"
|
93
135
|
- ".github/workflows/rspec.yml"
|
136
|
+
- ".github/workflows/type_check.yml"
|
94
137
|
- ".gitignore"
|
138
|
+
- ".mdl_rules.rb"
|
139
|
+
- ".mdlrc"
|
140
|
+
- ".quiet_quality.ci-cd.yml"
|
141
|
+
- ".quiet_quality.yml"
|
95
142
|
- ".rspec"
|
96
143
|
- ".rubocop.yml"
|
144
|
+
- CHANGELOG.md
|
97
145
|
- Gemfile
|
98
146
|
- LICENSE
|
99
147
|
- README.md
|
148
|
+
- Steepfile
|
100
149
|
- environment_helpers.gemspec
|
101
150
|
- lib/environment_helpers.rb
|
102
151
|
- lib/environment_helpers/access_helpers.rb
|
103
152
|
- lib/environment_helpers/boolean_helpers.rb
|
104
153
|
- lib/environment_helpers/datetime_helpers.rb
|
154
|
+
- lib/environment_helpers/enumerable_helpers.rb
|
105
155
|
- lib/environment_helpers/file_helpers.rb
|
106
156
|
- lib/environment_helpers/numeric_helpers.rb
|
107
157
|
- lib/environment_helpers/range_helpers.rb
|
108
158
|
- lib/environment_helpers/string_helpers.rb
|
109
159
|
- lib/environment_helpers/version.rb
|
160
|
+
- sig/environment_helpers.rbs
|
110
161
|
homepage: https://github.com/nevinera/environment_helpers
|
111
162
|
licenses:
|
112
163
|
- MIT
|
@@ -121,14 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
172
|
requirements:
|
122
173
|
- - ">="
|
123
174
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
175
|
+
version: 2.7.0
|
125
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
177
|
requirements:
|
127
178
|
- - ">="
|
128
179
|
- !ruby/object:Gem::Version
|
129
180
|
version: '0'
|
130
181
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
182
|
+
rubygems_version: 3.4.10
|
132
183
|
signing_key:
|
133
184
|
specification_version: 4
|
134
185
|
summary: A set of convenience methods for accessing environment data
|
data/.github/workflows/lint.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
name: Linters
|
2
|
-
|
3
|
-
on: [push]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
StandardRB:
|
7
|
-
runs-on: ubuntu-latest
|
8
|
-
steps:
|
9
|
-
- uses: actions/checkout@v2
|
10
|
-
|
11
|
-
- name: Set up ruby
|
12
|
-
uses: ruby/setup-ruby@v1
|
13
|
-
with:
|
14
|
-
ruby-version: 3.2
|
15
|
-
|
16
|
-
- name: Cache gems
|
17
|
-
uses: actions/cache@v1
|
18
|
-
with:
|
19
|
-
path: vendor/bundle
|
20
|
-
key: ${{ runner.os }}-linters-${{ hashFiles('Gemfile.lock') }}
|
21
|
-
restore-keys:
|
22
|
-
${{ runner.os }}-linters-
|
23
|
-
- name: Install gems
|
24
|
-
run: bundle install --jobs 4 --retry 3
|
25
|
-
|
26
|
-
- name: Run standard
|
27
|
-
run: bundle exec standardrb
|
28
|
-
|
29
|
-
- name: Run rubocop (complexity checks)
|
30
|
-
run: bundle exec rubocop --parallel
|