environment_helpers 0.0.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b923675b4ed251cc3ffe498b480923619622e9cb7a1ebbf2e3bde6bbae036e84
4
- data.tar.gz: 63a23ba984f9f1e67c2e01651cc6d6d73538fc7e8eda26516b56e748209b2bd8
3
+ metadata.gz: 8909c0a7ad45e4fc50777d074086126849b1b9a3907ecae5f5b6c5fafd547c3a
4
+ data.tar.gz: 59f2b7b8cd84a28cc24b545fc240f5145a38b4d445a60f63ef35b881d6ee2c50
5
5
  SHA512:
6
- metadata.gz: 7113d4d1727c3ffe4a1311c588105f5ebec6a9d877da6341ee4d5e12b998fbbb03bfd0543736dbacbdcb3fe38ebd19c4eb3eae5efe5b4352a86086dfadf47e53
7
- data.tar.gz: 35228c708df18bce2b56c6779f6047da0c3eaf62d922010136779e9e5c958ae66a5002006f2888ebc25be014448ff6515311811f692a498c95075941fadc298e
6
+ metadata.gz: 744fa0ee02661aa41df2a0bee2b88af5402d0ab5dfefa77e93aeabfccb44186c68e79da151ea926b85a0608c9c903f1925e877362d6d7cfad43f5d3172b3dbdb
7
+ data.tar.gz: 56099bbc01ff6226b63fedab0ed108eccb65775550782e1635ece461985ad1817e99340a2cedd01be724ee50bbf2d9def8e2cad005d2ae7299750cd418fd9e3c
@@ -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
@@ -1,3 +1,5 @@
1
1
  .ruby-version
2
2
  .ruby-gemset
3
3
  Gemfile.lock
4
+ *.gem
5
+ coverage/
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.
@@ -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.7.0")
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
@@ -28,8 +28,9 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = []
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_development_dependency "rspec", ">= 3.10"
32
- spec.add_development_dependency "pry"
33
- spec.add_development_dependency "standard"
34
- spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "rspec", "~> 3.10"
32
+ spec.add_development_dependency "simplecov", "~> 0.22.0"
33
+ spec.add_development_dependency "pry", "~> 0.14"
34
+ spec.add_development_dependency "standard", "~> 1.28"
35
+ spec.add_development_dependency "rubocop", "~> 1.50"
35
36
  end
@@ -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: [nil, true, false])
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
@@ -1,3 +1,3 @@
1
1
  module EnvironmentHelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: environment_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.1
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-24 00:00:00.000000000 Z
11
+ date: 2023-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
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.22.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.22.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '0.14'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '0.14'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: standard
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '1.28'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '1.28'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '1.50'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '1.50'
69
83
  description: |
70
84
  Convenience helpers for more simply accessing data passed to applications through the
71
85
  environment that may have types and/or defaults
@@ -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.7.0
122
+ version: 2.6.0
104
123
  required_rubygems_version: !ruby/object:Gem::Requirement
105
124
  requirements:
106
125
  - - ">="