{"id":22211296,"url":"https://github.com/danielshow/env_utils","last_synced_at":"2025-07-27T10:33:10.083Z","repository":{"id":56844643,"uuid":"463127717","full_name":"Danielshow/env_utils","owner":"Danielshow","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-16T19:38:00.000Z","size":35,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-31T14:15:28.037Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Danielshow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-24T11:47:36.000Z","updated_at":"2022-03-02T11:35:28.000Z","dependencies_parsed_at":"2022-09-09T19:11:25.109Z","dependency_job_id":null,"html_url":"https://github.com/Danielshow/env_utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danielshow%2Fenv_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danielshow%2Fenv_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danielshow%2Fenv_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danielshow%2Fenv_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Danielshow","download_url":"https://codeload.github.com/Danielshow/env_utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227551594,"owners_count":17786116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T20:22:28.023Z","updated_at":"2024-12-02T20:22:28.507Z","avatar_url":"https://github.com/Danielshow.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnvUtils\n\nEasily Get Environment Variables. This is the ruby-like version of [env-utils](https://github.com/BolajiOlajide/env-utils)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'env_utils'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install env_utils\n\n## get_env_var\n\nGets an environment variable. This returns nil if the environment variable isn't detected.\n\n```ruby\ninclude EnvUtils\n\nget_env_var(env_var_name, options)\n```\n\n### Options\n\n- `options.is_boolean` - Forces the value to be a boolean\n\n```ruby\n# returns true if the variable is 'true' else it returns false\nshouldAcceptCoins = get_env_var('SHOULD_ACCEPT_COINS', { boolean: true })\n```\n\n- `options.is_array` - If your env variable is a comma separated string you can get back an array instead.\n\n```ruby\n# PORTS='8080,9000,3000'\nPORTS = get_env_var('PORTS', { isArray: true }) # returns ['8080', '9000', '3000'];\n```\n\nIn the event that the variable is separated by something other than a comma, you can define the separator using `options.separator`.\n\n```ruby\nPORTS = '8080\u00269000\u00263000'\nPORTS = get_env_var('PORTS', { isArray: true, separator: '\u0026' }) # returns ['8080', '9000', '3000'];\n```\n\n- `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.\n  This only applies when `ENV['RAILS_ENV'] is 'development'`. Any other value of `RAILS_ENV` will not regard this option\n\n```ruby\nPORT = get_env_var('PORT', { dev_default: '1234' })\n# if ENV[\"PORT\"] is not set, the value of PORT will be `1234`\n```\n\n- `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\n\n```ruby\nPORT = get_env_var('PORT', { default: '1234' })\n# if ENV[\"PORT\"] is not set, the value of PORT will be `1234`\n```\n\n- `options.is_integer` - used to convert numeric-like variables into integer. Note: This will return 0 if value is not numeric-like.\n\n```ruby\n# if ENV[\"PORT\"] = '8080'\nPORT = get_env_var('PORT', { is_integer: true }) # returns 8080\n\n#  if ENV[\"PORT\"] = 'smash' - returns 0\nPORT = get_env_var('PORT', { is_integer: true }) # returns 0\n```\n\n- `options.is_float` - used to convert numeric-like variables into float. Note: This will return 0.0 if value is not a number\n\n```ruby\n# if ENV[\"PORT\"] = '8080.98'\nPORT = get_env_var('PORT', { is_float: true }) # returns 8080.98\n\n#  if ENV[\"PORT\"] = 'smash' - returns 0.0\nPORT = get_env_var('PORT', { is_float: true }) # returns 0.0\n```\n\n#### Utility Functions\n\n`env-utils` exports some utility functions that return `variables` in a certain type. This is just casting some variables to its type\n\n```ruby\n\n# You can make use of the utility functions and they return the appropriate types\n\nget_string_env('SENTRY_DSN') # will always return a string | undefined\n```\n\nN.B All utility functions have exactly the same signature as the `get_env_var` function.\n\n- `ENV` returns an environment variable as a string\n- `get_array_env` returns an environment variable as an array\n- `get_bool_env` returns an environment variable as a boolean\n- `get_integer_env` returns an environment variable as an integer\n- `get_float_env` returns an environment variable as a float\n\n## Development\n\nAfter 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.\n\nTo 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).\n\n## Contributing\n\nBug 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).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone 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).\n\n## Credits\n\n- [Bolaji Olajide](https://github.com/BolajiOlajide)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielshow%2Fenv_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielshow%2Fenv_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielshow%2Fenv_utils/lists"}