environment_helpers 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/environment_helpers.gemspec +5 -5
- data/lib/environment_helpers/range_helpers.rb +42 -0
- data/lib/environment_helpers/version.rb +1 -1
- data/lib/environment_helpers.rb +3 -0
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 202ea78421b65c63b2d3151a55ddfc891aab67569d67dceba358939f0b89fcd7
|
4
|
+
data.tar.gz: 82344f0d77473dd80a467a915c33d5897ae763eaa8d9faa18e81b9b9c99e9774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b0d5146de039a774301fb24266f4d2cdb467e095e0915121771b543aed10782c88e80f5c9c24e234b6cf9821e76637232f7220812061774599ec03b0f500b9
|
7
|
+
data.tar.gz: 3aa3c4435e7e7a9ebf83d1fbf9277e55a7fb12be6280119045ab2dbaf80f20715116a357f09dca9884a57772c889890defa509df7cf2a551ee3ecf8f8f8cbe9a
|
data/README.md
CHANGED
@@ -34,6 +34,7 @@ methods onto `ENV` for your use.
|
|
34
34
|
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
|
+
ENV.integer_range("ID_RANGE", default: (500..6000))
|
37
38
|
ENV.integer("MAX_THREAD_COUNT", default: 5)
|
38
39
|
ENV.date("SCHEDULED_DATE", required: true, format: "%Y-%m-%d")
|
39
40
|
```
|
@@ -51,6 +52,8 @@ The available methods added to `ENV`:
|
|
51
52
|
a fair variety of strings to map onto those boolean value, though you should probably just use
|
52
53
|
"true" and "false" really. If you specify `required: true` and get a value like "maybe?", it'll
|
53
54
|
raise an `EnvironmentHelpers::InvalidBooleanText` exception.
|
55
|
+
* `integer_range` - produces an integer Range object. It accepts `N-N`, `N..N`, or `N...N`, (the
|
56
|
+
latter means 'excluding the upper bound, as in ruby).
|
54
57
|
* `integer` - produces an integer from the environment variable, by calling `to_i` on it (if it's
|
55
58
|
present). Note that this means that providing a value like "hello" means you'll get `0`, since
|
56
59
|
that's what ruby does when you call `"hello".to_i`.
|
data/environment_helpers.gemspec
CHANGED
@@ -28,9 +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", "
|
32
|
-
spec.add_development_dependency "simplecov"
|
33
|
-
spec.add_development_dependency "pry"
|
34
|
-
spec.add_development_dependency "standard"
|
35
|
-
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"
|
36
36
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module EnvironmentHelpers
|
2
|
+
module RangeHelpers
|
3
|
+
def integer_range(name, default: nil, required: false)
|
4
|
+
check_default_type(:integer_range, default, Range)
|
5
|
+
check_range_endpoint(:integer_range, default.begin) if default
|
6
|
+
check_range_endpoint(:integer_range, default.end) if default
|
7
|
+
|
8
|
+
text = fetch_value(name, required: required)
|
9
|
+
range = parse_range_from(text)
|
10
|
+
return range if range
|
11
|
+
return default unless required
|
12
|
+
fail(InvalidRangeText, "Required Integer Range environment variable #{name} had inappropriate content '#{text}'")
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def check_range_endpoint(context, value)
|
18
|
+
return if value.is_a?(Integer)
|
19
|
+
fail(BadDefault, "Invalid endpoint for default range of #{context} - must be Integer")
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_range_bound_from(text)
|
23
|
+
return nil if text.nil?
|
24
|
+
return nil if text.empty?
|
25
|
+
text.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_range_from(text)
|
29
|
+
text =~ /\A(\d*)(-|\.\.|\.\.\.)(\d*)\z/
|
30
|
+
lower_bound = parse_range_bound_from($1)
|
31
|
+
separator = $2
|
32
|
+
upper_bound = parse_range_bound_from($3)
|
33
|
+
|
34
|
+
return nil if lower_bound.nil? || upper_bound.nil?
|
35
|
+
if separator == "..."
|
36
|
+
(lower_bound...upper_bound)
|
37
|
+
else
|
38
|
+
(lower_bound..upper_bound)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/environment_helpers.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "./environment_helpers/access_helpers"
|
2
2
|
require_relative "./environment_helpers/string_helpers"
|
3
3
|
require_relative "./environment_helpers/boolean_helpers"
|
4
|
+
require_relative "./environment_helpers/range_helpers"
|
4
5
|
require_relative "./environment_helpers/numeric_helpers"
|
5
6
|
require_relative "./environment_helpers/datetime_helpers"
|
6
7
|
|
@@ -11,12 +12,14 @@ module EnvironmentHelpers
|
|
11
12
|
|
12
13
|
InvalidValue = Class.new(Error)
|
13
14
|
InvalidBooleanText = Class.new(InvalidValue)
|
15
|
+
InvalidRangeText = Class.new(InvalidValue)
|
14
16
|
InvalidIntegerText = Class.new(InvalidValue)
|
15
17
|
InvalidDateText = Class.new(InvalidValue)
|
16
18
|
|
17
19
|
include AccessHelpers
|
18
20
|
include StringHelpers
|
19
21
|
include BooleanHelpers
|
22
|
+
include RangeHelpers
|
20
23
|
include NumericHelpers
|
21
24
|
include DatetimeHelpers
|
22
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: environment_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Mueller
|
@@ -14,72 +14,72 @@ dependencies:
|
|
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
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.22.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.22.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: standard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.28'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.28'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.50'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.50'
|
83
83
|
description: |
|
84
84
|
Convenience helpers for more simply accessing data passed to applications through the
|
85
85
|
environment that may have types and/or defaults
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/environment_helpers/boolean_helpers.rb
|
104
104
|
- lib/environment_helpers/datetime_helpers.rb
|
105
105
|
- lib/environment_helpers/numeric_helpers.rb
|
106
|
+
- lib/environment_helpers/range_helpers.rb
|
106
107
|
- lib/environment_helpers/string_helpers.rb
|
107
108
|
- lib/environment_helpers/version.rb
|
108
109
|
homepage: https://github.com/nevinera/environment_helpers
|