{"id":16102356,"url":"https://github.com/sshaw/env_var","last_synced_at":"2025-04-06T01:11:46.362Z","repository":{"id":56844646,"uuid":"193199233","full_name":"sshaw/env_var","owner":"sshaw","description":"Check if an environment variable is set to an enabled or disabled value; fetch an environment variable as an Array of Strings or Symbols","archived":false,"fork":false,"pushed_at":"2020-08-08T02:44:54.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T17:53:52.432Z","etag":null,"topics":["12-factor","environment","environment-variables","ruby","twelve-factor"],"latest_commit_sha":null,"homepage":"","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/sshaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-22T06:20:39.000Z","updated_at":"2020-08-08T02:44:56.000Z","dependencies_parsed_at":"2022-09-07T20:10:13.674Z","dependency_job_id":null,"html_url":"https://github.com/sshaw/env_var","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fenv_var","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fenv_var/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fenv_var/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fenv_var/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/env_var/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419871,"owners_count":20936013,"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":["12-factor","environment","environment-variables","ruby","twelve-factor"],"created_at":"2024-10-09T18:53:37.247Z","updated_at":"2025-04-06T01:11:46.327Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnvVar\n\n[![Build Status](https://travis-ci.org/sshaw/env_var.svg?branch=master)](https://travis-ci.org/sshaw/env_var)\n\nCheck if an environment variable is set to an enabled or disabled value.\nFetch an environment variable as an Array of `String`s or `Symbol`s.\n\n## Usage\n\n### `enabled?`/`disabled?`\n\nSet an environment variable:\n```\nexport VARIABLE_NAME=1     # enabled\nexport VARIABLE_NAME=true  # enabled\nexport VARIABLE_NAME=0     # disabled\nexport VARIABLE_NAME=false # disabled\n```\n\nAnd check if it's enabled or disabled:\n```rb\nrequire \"$ENV\"\n\nenable_foo if $ENV.enabled?(\"VARIABLE_NAME\")\ndisable_foo if $ENV.disabled?(\"VARIABLE_NAME\")\n```\n\nNote that if the environment variable **is not set** `enabled?` and `disabled?` **can both be `false`**.\nIf something is not enabled that does not mean it was explicitly disabled.\n\nDon't do this:\n```rb\nif !$ENV.enabled?(\"VARIABLE_NAME\")\nif !$ENV.disabled?(\"VARIABLE_NAME\")\n```\n\nDo this:\n```rb\nif $ENV.disabled?(\"VARIABLE_NAME\")\nif $ENV.enabled?(\"VARIABLE_NAME\")\n```\n\n### `$ENV::W`\n\nReturn an environment variable's value as an `Array` of words (`String`s):\n\n\n```\nexport VARIABLE_NAME=\"a,b,c\"\nexport ANOTHER_VARIABLE=\n```\n\nThen in Ruby:\n\n```rb\n$ENV::W[\"VARIABLE_NAME\"]     # [\"a\", \"b\", \"c\"]\n$ENV::W[\"ANOTHER_VARIABLE\"]  # []\n\n# Or\n$ENV.W(\"VARIABLE_NAME\")      # [\"a\", \"b\", \"c\"]\n$ENV.w(\"VARIABLE_NAME\")      # [\"a\", \"b\", \"c\"]\n```\n\nMnemonic `%w(a b c)`.\n\n### `$ENV::I`\n\nReturn an environment variable's value as an `Array` of `Symbol`s:\n\n```rb\n$ENV::I[\"VARIABLE_NAME\"]  # [:a, :b, :c]\n\n# Or\n$ENV.I(\"VARIABLE_NAME\")   # [:a, :b, :c]\n$ENV.i(\"VARIABLE_NAME\")   # [:a, :b, :c]\n```\n\nMnemonic `%i(a b c)`.\n\n### Otherwise, Use it Like You Would `ENV`\n\n```rb\np $ENV[\"VARIABLE_NAME\"]\np $ENV.delete(\"VARIABLE_NAME\")\n$ENV.each { |name, value| ... }\n```\n\n## Without `$ENV`\n\n```rb\nrequire \"env_var\"\n\nenable_foo if EnvVar.enabled?(\"VARIABLE_NAME\")\ndisable_foo if EnvVar.disabled?(\"VARIABLE_NAME\")\np EnvVar[\"VARIABLE_NAME\"]\np EnvVar.delete(\"VARIABLE_NAME\")\nEnvVar.each { |name, value| ... }\n```\n\n## Monkey Patch\n\n```rb\nrequire \"env_var/env\"\n\nenable_foo if ENV.enabled?(\"VARIABLE_NAME\")\ndisable_bar if ENV.disabled?(\"VARIABLE_NAME\")\np ENV::i[\"VARIABLE_NAME\"]\np ENV::w[\"VARIABLE_NAME\"]\n\n# ENV::W, ENV::I do not work\n```\n\n## Why?\n\nGot tired of writing this over and over in various applications:\n\n```rb\nenable_foo if %w[true 1 on].include?(ENV[\"ENABLE_FOO\"])\n```\n\n## See Also\n\n- [Envied](https://github.com/eval/envied) - Ensures presence and type of your app's ENV-variables\n\n## Author\n\nSkye Shaw (skye DOT shaw AT gmail )\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fenv_var","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Fenv_var","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fenv_var/lists"}