environment_helpers 0.0.1 → 1.0.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/lint.yml +30 -0
- data/.github/workflows/rspec.yml +33 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +21 -0
- data/LICENSE +20 -0
- data/README.md +5 -0
- data/environment_helpers.gemspec +2 -1
- data/lib/environment_helpers/boolean_helpers.rb +1 -4
- data/lib/environment_helpers/datetime_helpers.rb +24 -0
- data/lib/environment_helpers/version.rb +1 -1
- data/lib/environment_helpers.rb +3 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab82696a30367d94de8f033006be9fc63883b3d300075f97e73513e62427e0bf
|
4
|
+
data.tar.gz: 0bef7e80bc554b195be934e2fecc70908756e9951ad2db1805445ff20a7297c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b693dd3fe48277cd352cfd30d5f455fe1b14dbaf4b692f5fe603b00b83e5d621c7d6f6680b12a413da44155b268da42e365115373ba491eb4a646639445373b1
|
7
|
+
data.tar.gz: 902d55c02d71b6b7211fb8bbe76f2d6a7c805857491c170d214794ee8b9919df877d3903f0649f42a60546e168acb0de22828d106bb5a51874993320a7d54c2b
|
@@ -0,0 +1,30 @@
|
|
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
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: RSpec
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
RSpec:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', 'head']
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
|
16
|
+
- name: Set up ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
|
21
|
+
- name: Cache gems
|
22
|
+
uses: actions/cache@v3
|
23
|
+
with:
|
24
|
+
path: vendor/bundle
|
25
|
+
key: ${{ runner.os }}-rspec-${{ matrix.ruby-version }}-${{ hashFiles('Gemfile.lock') }}
|
26
|
+
restore-keys:
|
27
|
+
${{ runner.os }}-rspec-${{ matrix.ruby-version }}-
|
28
|
+
|
29
|
+
- name: Install gems
|
30
|
+
run: bundle install --jobs 4 --retry 3
|
31
|
+
|
32
|
+
- name: Run RSpec
|
33
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
SuggestExtensions: false
|
4
|
+
DisabledByDefault: true
|
5
|
+
|
6
|
+
Metrics/AbcSize:
|
7
|
+
Max: 15
|
8
|
+
Metrics/CyclomaticComplexity:
|
9
|
+
Max: 8
|
10
|
+
Metrics/PerceivedComplexity:
|
11
|
+
Max: 7
|
12
|
+
|
13
|
+
Metrics/ClassLength:
|
14
|
+
CountComments: false
|
15
|
+
Max: 150
|
16
|
+
Metrics/MethodLength:
|
17
|
+
CountComments: false
|
18
|
+
Max: 15
|
19
|
+
Metrics/ParameterLists:
|
20
|
+
Max: 5
|
21
|
+
CountKeywordArgs: true
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2023 Eric Mueller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ ENV.string("APP_NAME", default: "local")
|
|
35
35
|
ENV.symbol("BUSINESS_DOMAIN", default: :engineering, required: true)
|
36
36
|
ENV.boolean("ENABLE_FEATURE_FOO", default: false)
|
37
37
|
ENV.integer("MAX_THREAD_COUNT", default: 5)
|
38
|
+
ENV.date("SCHEDULED_DATE", required: true, format: "%Y-%m-%d")
|
38
39
|
```
|
39
40
|
|
40
41
|
Each of the supplied methods takes a positional parameter for the name of the environment variable,
|
@@ -53,3 +54,7 @@ The available methods added to `ENV`:
|
|
53
54
|
* `integer` - produces an integer from the environment variable, by calling `to_i` on it (if it's
|
54
55
|
present). Note that this means that providing a value like "hello" means you'll get `0`, since
|
55
56
|
that's what ruby does when you call `"hello".to_i`.
|
57
|
+
* `date` - produces a `Date` object, using `Date.strptime`. The default format string is `%Y-%m-%d`,
|
58
|
+
which would parse a date like `2023-12-25`. It will handle invalid values (or format strings) like
|
59
|
+
the variable not being present, though if it's specified as `required`, you will see a different
|
60
|
+
exception in each case.
|
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.6.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
31
|
spec.add_development_dependency "rspec", ">= 3.10"
|
32
|
+
spec.add_development_dependency "simplecov"
|
32
33
|
spec.add_development_dependency "pry"
|
33
34
|
spec.add_development_dependency "standard"
|
34
35
|
spec.add_development_dependency "rubocop"
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "set"
|
2
|
-
|
3
1
|
module EnvironmentHelpers
|
4
2
|
module BooleanHelpers
|
5
3
|
TRUTHY_STRINGS = %w[true yes on enabled enable allow t y 1 ok okay].to_set
|
@@ -7,10 +5,9 @@ module EnvironmentHelpers
|
|
7
5
|
BOOLEAN_VALUES = [true, false, nil].to_set
|
8
6
|
|
9
7
|
def boolean(name, default: nil, required: false)
|
10
|
-
check_default_value(:boolean, default, allow:
|
8
|
+
check_default_value(:boolean, default, allow: BOOLEAN_VALUES)
|
11
9
|
text = fetch_value(name, required: required)
|
12
10
|
|
13
|
-
return default if text.nil?
|
14
11
|
return true if truthy_text?(text)
|
15
12
|
return false if falsey_text?(text)
|
16
13
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
module EnvironmentHelpers
|
4
|
+
module DatetimeHelpers
|
5
|
+
def date(name, format: "%Y-%m-%d", default: nil, required: false)
|
6
|
+
check_default_type(:date, default, Date)
|
7
|
+
text = fetch_value(name, required: required)
|
8
|
+
date = parse_date_from(text, format: format)
|
9
|
+
|
10
|
+
return date if date
|
11
|
+
return default unless required
|
12
|
+
fail(InvalidDateText, "Required date environment variable #{name} had inappropriate content '#{text}'")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def parse_date_from(text, format:)
|
18
|
+
return nil if text.nil?
|
19
|
+
Date.strptime(text, format)
|
20
|
+
rescue ArgumentError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/environment_helpers.rb
CHANGED
@@ -2,6 +2,7 @@ require_relative "./environment_helpers/access_helpers"
|
|
2
2
|
require_relative "./environment_helpers/string_helpers"
|
3
3
|
require_relative "./environment_helpers/boolean_helpers"
|
4
4
|
require_relative "./environment_helpers/numeric_helpers"
|
5
|
+
require_relative "./environment_helpers/datetime_helpers"
|
5
6
|
|
6
7
|
module EnvironmentHelpers
|
7
8
|
Error = Class.new(::StandardError)
|
@@ -11,11 +12,13 @@ module EnvironmentHelpers
|
|
11
12
|
InvalidValue = Class.new(Error)
|
12
13
|
InvalidBooleanText = Class.new(InvalidValue)
|
13
14
|
InvalidIntegerText = Class.new(InvalidValue)
|
15
|
+
InvalidDateText = Class.new(InvalidValue)
|
14
16
|
|
15
17
|
include AccessHelpers
|
16
18
|
include StringHelpers
|
17
19
|
include BooleanHelpers
|
18
20
|
include NumericHelpers
|
21
|
+
include DatetimeHelpers
|
19
22
|
end
|
20
23
|
|
21
24
|
ENV.extend(EnvironmentHelpers)
|
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: 0.0
|
4
|
+
version: 1.0.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-04-
|
11
|
+
date: 2023-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,14 +89,19 @@ executables: []
|
|
75
89
|
extensions: []
|
76
90
|
extra_rdoc_files: []
|
77
91
|
files:
|
92
|
+
- ".github/workflows/lint.yml"
|
93
|
+
- ".github/workflows/rspec.yml"
|
78
94
|
- ".gitignore"
|
79
95
|
- ".rspec"
|
96
|
+
- ".rubocop.yml"
|
80
97
|
- Gemfile
|
98
|
+
- LICENSE
|
81
99
|
- README.md
|
82
100
|
- environment_helpers.gemspec
|
83
101
|
- lib/environment_helpers.rb
|
84
102
|
- lib/environment_helpers/access_helpers.rb
|
85
103
|
- lib/environment_helpers/boolean_helpers.rb
|
104
|
+
- lib/environment_helpers/datetime_helpers.rb
|
86
105
|
- lib/environment_helpers/numeric_helpers.rb
|
87
106
|
- lib/environment_helpers/string_helpers.rb
|
88
107
|
- lib/environment_helpers/version.rb
|
@@ -100,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
119
|
requirements:
|
101
120
|
- - ">="
|
102
121
|
- !ruby/object:Gem::Version
|
103
|
-
version: 2.
|
122
|
+
version: 2.6.0
|
104
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
124
|
requirements:
|
106
125
|
- - ">="
|