env_utils 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b944a931a159da7ea718858bde07767a06a45730c30c06e1c4382808eb9b912b
4
+ data.tar.gz: 3684587a96dbc90955aa41c05cf8068d5fa70001dec2348d1ef565188ce122ec
5
+ SHA512:
6
+ metadata.gz: 41768737f39af1e6b07c3e4bc7dfe18e4388810a1fffe61de45a395df511c7fd43e4c01f5050157c60262da48a7727647964da0390f56dea1bd03a59d1f9a3df
7
+ data.tar.gz: 98eb78041aaae79ca2ef61fc037882b3464d9d7c60b17763e00c66cacad690785019aa3eeab9bba7119f8498e1f0984ac20a5a75d1ced64d3d38b8387bbbfe31
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: true
17
+ Max: 50
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: false
24
+
25
+ Metrics/ParameterLists:
26
+ Enabled: true
27
+ Max: 6
28
+ Exclude:
29
+ - 'spec/**/*'
30
+
31
+ Metrics/BlockLength:
32
+ Enabled: true
33
+ Max: 25
34
+ Exclude:
35
+ - 'spec/**/*'
36
+
37
+ Style/IfUnlessModifier:
38
+ Enabled: false
39
+
40
+ Metrics/CyclomaticComplexity:
41
+ Enabled: true
42
+ Max: 15
43
+
44
+ Metrics/PerceivedComplexity:
45
+ Enabled: true
46
+ Max: 15
47
+
48
+ Metrics/ModuleLength:
49
+ Enabled: true
50
+ Max: 150
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-02-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at danielshotonwa53@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in env_utils.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rubocop", "~> 1.7"
10
+
11
+ gem "rspec", "~> 3.11"
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ env_utils (0.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ parallel (1.21.0)
12
+ parser (3.0.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ rubocop (1.23.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.12.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.13.0)
41
+ parser (>= 3.0.1.1)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.1.0)
44
+
45
+ PLATFORMS
46
+ x86_64-darwin-20
47
+ x86_64-linux
48
+
49
+ DEPENDENCIES
50
+ env_utils!
51
+ rake (~> 13.0)
52
+ rspec (~> 3.11)
53
+ rubocop (~> 1.7)
54
+
55
+ BUNDLED WITH
56
+ 2.2.26
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Danielshow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # EnvUtilsRuby
2
+
3
+ Easily Get Environment Variables. This is the ruby-like version of [env-utils](https://github.com/BolajiOlajide/env-utils)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'env_utils'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install env_utils
20
+
21
+ ## get_env_var
22
+
23
+ Gets an environment variable. This returns nil if the environment variable isn't detected.
24
+
25
+ ```ruby
26
+ include EnvUtils
27
+
28
+ get_env_var(env_var_name, options)
29
+ ```
30
+
31
+ ### Options
32
+
33
+ - `options.is_boolean` - Forces the value to be a boolean
34
+
35
+ ```ruby
36
+ # returns true if the variable is 'true' else it returns false
37
+ shouldAcceptCoins = get_env_var('SHOULD_ACCEPT_COINS', { boolean: true })
38
+ ```
39
+
40
+ - `options.is_array` - If your env variable is a comma separated string you can get back an array instead.
41
+
42
+ ```ruby
43
+ # PORTS='8080,9000,3000'
44
+ PORTS = get_env_var('PORTS', { isArray: true }) # returns ['8080', '9000', '3000'];
45
+ ```
46
+
47
+ In the event that the variable is separated by something other than a comma, you can define the separator using `options.separator`.
48
+
49
+ ```ruby
50
+ PORTS = '8080&9000&3000'
51
+ PORTS = get_env_var('PORTS', { isArray: true, separator: '&' }) # returns ['8080', '9000', '3000'];
52
+ ```
53
+
54
+ - `options.dev_default` - used to specify a development-environment-only fallback for the variable. If the variable is nil, the `devDefault` is returned in it's stead.
55
+ This only applies when `ENV['RAILS_ENV'] is 'development'`. Any other value of `RAILS_ENV` will not regard this option
56
+
57
+ ```ruby
58
+ PORT = get_env_var('PORT', { dev_default: '1234' })
59
+ # if ENV["PORT"] is not set, the value of PORT will be `1234`
60
+ ```
61
+
62
+ - `options.default` - used to specify a default fallback for the variable. If the variable is nil, the `default` is returned in it's stead, dev_default overides default in development environment
63
+
64
+ ```ruby
65
+ PORT = get_env_var('PORT', { default: '1234' })
66
+ # if ENV["PORT"] is not set, the value of PORT will be `1234`
67
+ ```
68
+
69
+ - `options.is_integer` - used to convert numeric-like variables into integer. Note: This will return 0 if value is not numeric-like.
70
+
71
+ ```ruby
72
+ # if ENV["PORT"] = '8080'
73
+ PORT = get_env_var('PORT', { is_integer: true }) # returns 8080
74
+
75
+ # if ENV["PORT"] = 'smash' - returns 0
76
+ PORT = get_env_var('PORT', { is_integer: true }) # returns 0
77
+ ```
78
+
79
+ - `options.is_float` - used to convert numeric-like variables into float. Note: This will return 0.0 if value is not a number
80
+
81
+ ```ruby
82
+ # if ENV["PORT"] = '8080.98'
83
+ PORT = get_env_var('PORT', { is_float: true }) # returns 8080.98
84
+
85
+ # if ENV["PORT"] = 'smash' - returns 0.0
86
+ PORT = get_env_var('PORT', { is_float: true }) # returns 0.0
87
+ ```
88
+
89
+ #### Utility Functions
90
+
91
+ `env-utils` exports some utility functions that return `variables` in a certain type. This is just casting some variables to its type
92
+
93
+ ```ruby
94
+
95
+ # You can make use of the utility functions and they return the appropriate types
96
+
97
+ get_string_env('SENTRY_DSN') # will always return a string | undefined
98
+ ```
99
+
100
+ N.B All utility functions have exactly the same signature as the `get_env_var` function.
101
+
102
+ - `ENV` returns an environment variable as a string
103
+ - `get_array_env` returns an environment variable as an array
104
+ - `get_bool_env` returns an environment variable as a boolean
105
+ - `get_integer_env` returns an environment variable as an integer
106
+ - `get_float_env` returns an environment variable as a float
107
+
108
+ ## Development
109
+
110
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
111
+
112
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
113
+
114
+ ## Contributing
115
+
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danielshow/env_utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/env_utils/blob/master/CODE_OF_CONDUCT.md).
117
+
118
+ ## License
119
+
120
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
121
+
122
+ ## Code of Conduct
123
+
124
+ Everyone interacting in the Env::Utils::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/danielshow/env_utils/blob/master/CODE_OF_CONDUCT.md).
125
+
126
+ ## Credits
127
+
128
+ - [Bolaji Olajide](https://github.com/BolajiOlajide)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+ require "rspec/core/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :rubocop
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "env_utils"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module EnvUtils
2
+ VERSION = "0.1.3"
3
+ end
data/lib/env_utils.rb ADDED
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "env_utils/version"
4
+
5
+ # EnvUtils is a library for getting environment variables.
6
+ module EnvUtils
7
+ class Error < StandardError; end
8
+
9
+ # Get the value of an environment variable.
10
+ # @param [String] name the name of the environment variable
11
+ # @return [String, nil] the value of the environment variable, or nil if it is not set
12
+
13
+ def get_env_var(key, options = {})
14
+ fallback = ENV["RAILS_ENV"] == "development" ? options[:dev_default] : nil
15
+ fallback ||= options[:default]
16
+
17
+ env_value = ENV[key] || fallback
18
+
19
+ is_string = env_value.is_a?(String)
20
+
21
+ return nil if env_value.nil? && !options[:is_boolean]
22
+
23
+ return env_value == "true" if options[:is_boolean]
24
+
25
+ return env_value.split(options[:separator] || ",").collect(&:strip) if options[:is_array] && is_string
26
+
27
+ return env_value.to_i if options[:is_integer] && is_string
28
+
29
+ return env_value.to_f if options[:is_float] && is_string
30
+
31
+ env_value
32
+ end
33
+
34
+ def get_string_env(key, options = {})
35
+ options.merge!({ is_integer: false, is_boolean: false, is_array: false })
36
+ get_env_var(key, options)
37
+ end
38
+
39
+ def get_integer_env(key, options = {})
40
+ options.merge!({ is_integer: true, is_boolean: false, is_array: false })
41
+ get_env_var(key, options)
42
+ end
43
+
44
+ def get_float_env(key, options = {})
45
+ options.merge!({ is_integer: false, is_boolean: false, is_array: false, is_float: true })
46
+ get_env_var(key, options)
47
+ end
48
+
49
+ def get_bool_env(key, options = {})
50
+ options.merge!({ is_integer: false, is_boolean: true, is_array: false })
51
+
52
+ get_env_var(key, options)
53
+ end
54
+
55
+ def get_array_env(key, options = {})
56
+ options.merge!({ is_array: true })
57
+
58
+ get_env_var(key, options)
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Danielshow
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ description: This gem provides Ruby utilities for Env
28
+ email:
29
+ - danielshotonwa53@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/env_utils.rb
46
+ - lib/env_utils/version.rb
47
+ homepage: https://github.com/danielshow/env_utils
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/danielshow/env_utils
52
+ source_code_uri: https://github.com/danielshow/env_utils
53
+ changelog_uri: https://github.com/danielshow/env_utils/blob/main/CHANGELOG.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.5.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.0.3.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Ruby utilities for Env
73
+ test_files: []