environment_helpers 1.1.0 → 1.2.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 +4 -1
- data/lib/environment_helpers/file_helpers.rb +12 -0
- data/lib/environment_helpers/version.rb +1 -1
- data/lib/environment_helpers.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdd872a3aa32975aeeb47dbe0236e1571c41c47632c0fcae86fea957f8c1eafa
|
4
|
+
data.tar.gz: d9f41beec0bba097c4bda2c0aa6c365c0967106843daeb79650e58b08c2e6a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0adb44b8ce267e6e6d072c3f7e474c55fce9709bb924736b5f8abad59d54cd0e88d401892adbf850c589abfed455eec7925077fc2b62393984943c636c938b
|
7
|
+
data.tar.gz: c64a226be91f881470d39671fc8a559927c475ea9e32e347ad54a2dae02dc534190a743f1927601bd321e2acbe37d872c49c66251c1fad9be2f74e3586025894
|
data/README.md
CHANGED
@@ -30,12 +30,13 @@ methods onto `ENV` for your use.
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
```
|
33
|
+
```shell
|
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
37
|
ENV.integer_range("ID_RANGE", default: (500..6000))
|
38
38
|
ENV.integer("MAX_THREAD_COUNT", default: 5)
|
39
|
+
ENV.file_path("FILE_PATH", default: "/some/path", required: true)
|
39
40
|
ENV.date("SCHEDULED_DATE", required: true, format: "%Y-%m-%d")
|
40
41
|
```
|
41
42
|
|
@@ -46,6 +47,7 @@ isn't present in the environment. If `required` is set to a truthy value, then i
|
|
46
47
|
present in the environment, an `EnvironmentHelpers::MissingVariableError` is raised.
|
47
48
|
|
48
49
|
The available methods added to `ENV`:
|
50
|
+
|
49
51
|
* `string` - environment values are already strings, so this is the simplest of the methods.
|
50
52
|
* `symbol` - produces a symbol, and enforces that the default value is either `nil` or a Symbol.
|
51
53
|
* `boolean` - produces `nil`, `true`, or `false` (and only allows those as defaults). Supports..
|
@@ -57,6 +59,7 @@ The available methods added to `ENV`:
|
|
57
59
|
* `integer` - produces an integer from the environment variable, by calling `to_i` on it (if it's
|
58
60
|
present). Note that this means that providing a value like "hello" means you'll get `0`, since
|
59
61
|
that's what ruby does when you call `"hello".to_i`.
|
62
|
+
* `file_path` - produces a `Pathname` initialized with the path specified by the environment variable.
|
60
63
|
* `date` - produces a `Date` object, using `Date.strptime`. The default format string is `%Y-%m-%d`,
|
61
64
|
which would parse a date like `2023-12-25`. It will handle invalid values (or format strings) like
|
62
65
|
the variable not being present, though if it's specified as `required`, you will see a different
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module EnvironmentHelpers
|
4
|
+
module FileHelpers
|
5
|
+
def file_path(name, default: nil, required: false)
|
6
|
+
check_default_type(:file_path, default, String)
|
7
|
+
path = fetch_value(name, required: required) || default
|
8
|
+
return nil if path.nil?
|
9
|
+
Pathname.new(path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/environment_helpers.rb
CHANGED
@@ -3,6 +3,7 @@ require_relative "./environment_helpers/string_helpers"
|
|
3
3
|
require_relative "./environment_helpers/boolean_helpers"
|
4
4
|
require_relative "./environment_helpers/range_helpers"
|
5
5
|
require_relative "./environment_helpers/numeric_helpers"
|
6
|
+
require_relative "./environment_helpers/file_helpers"
|
6
7
|
require_relative "./environment_helpers/datetime_helpers"
|
7
8
|
|
8
9
|
module EnvironmentHelpers
|
@@ -21,6 +22,7 @@ module EnvironmentHelpers
|
|
21
22
|
include BooleanHelpers
|
22
23
|
include RangeHelpers
|
23
24
|
include NumericHelpers
|
25
|
+
include FileHelpers
|
24
26
|
include DatetimeHelpers
|
25
27
|
end
|
26
28
|
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Mueller
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/environment_helpers/access_helpers.rb
|
103
103
|
- lib/environment_helpers/boolean_helpers.rb
|
104
104
|
- lib/environment_helpers/datetime_helpers.rb
|
105
|
+
- lib/environment_helpers/file_helpers.rb
|
105
106
|
- lib/environment_helpers/numeric_helpers.rb
|
106
107
|
- lib/environment_helpers/range_helpers.rb
|
107
108
|
- lib/environment_helpers/string_helpers.rb
|