environment_helpers 1.1.0 → 1.2.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: 202ea78421b65c63b2d3151a55ddfc891aab67569d67dceba358939f0b89fcd7
4
- data.tar.gz: 82344f0d77473dd80a467a915c33d5897ae763eaa8d9faa18e81b9b9c99e9774
3
+ metadata.gz: 71bfb123e7f90d29f9e038849bc995207b9c11b166aae7e0938cf162e7ed70f5
4
+ data.tar.gz: bb88e8d31c0c343a54f7be6a6919af08446a2a9fff973868b9ba22a9f1fc3f9a
5
5
  SHA512:
6
- metadata.gz: f7b0d5146de039a774301fb24266f4d2cdb467e095e0915121771b543aed10782c88e80f5c9c24e234b6cf9821e76637232f7220812061774599ec03b0f500b9
7
- data.tar.gz: 3aa3c4435e7e7a9ebf83d1fbf9277e55a7fb12be6280119045ab2dbaf80f20715116a357f09dca9884a57772c889890defa509df7cf2a551ee3ecf8f8f8cbe9a
6
+ metadata.gz: f9adafc223d6c2edff2c4179bb86d172e2febe28d8761a2d55b9b76db02d6076ce981229cd8f758c905c4e4e524ad4b6b6e589ff55ced624fbc510ad8a183ed1
7
+ data.tar.gz: 7d6ae5d630de28a2d5db1776d06ed7d2a6117a905b66c12aa61b2b7fe5c4dd64dd8cd5e764c450fcf846b077ee23c7f74f6bd393d3cec8b161f6365a27cd498b
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
@@ -1,3 +1,3 @@
1
1
  module EnvironmentHelpers
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -1,8 +1,13 @@
1
+ # 'set' doesn't need requiring after ruby 3.2, but it won't hurt anything.
2
+ # And we're compatible back to 2.6
3
+ require "set" # rubocop:disable Lint/RedundantRequireStatement
4
+
1
5
  require_relative "./environment_helpers/access_helpers"
2
6
  require_relative "./environment_helpers/string_helpers"
3
7
  require_relative "./environment_helpers/boolean_helpers"
4
8
  require_relative "./environment_helpers/range_helpers"
5
9
  require_relative "./environment_helpers/numeric_helpers"
10
+ require_relative "./environment_helpers/file_helpers"
6
11
  require_relative "./environment_helpers/datetime_helpers"
7
12
 
8
13
  module EnvironmentHelpers
@@ -21,6 +26,7 @@ module EnvironmentHelpers
21
26
  include BooleanHelpers
22
27
  include RangeHelpers
23
28
  include NumericHelpers
29
+ include FileHelpers
24
30
  include DatetimeHelpers
25
31
  end
26
32
 
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.1.0
4
+ version: 1.2.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-25 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -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
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubygems_version: 3.1.6
131
+ rubygems_version: 3.3.26
131
132
  signing_key:
132
133
  specification_version: 4
133
134
  summary: A set of convenience methods for accessing environment data