{"id":15590373,"url":"https://github.com/bkeepers/envy","last_synced_at":"2025-05-05T19:30:03.952Z","repository":{"id":19942628,"uuid":"23209313","full_name":"bkeepers/envy","owner":"bkeepers","description":"a schema for your application's environment variables","archived":false,"fork":false,"pushed_at":"2021-04-08T16:42:02.000Z","size":103,"stargazers_count":21,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T23:05:08.226Z","etag":null,"topics":[],"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/bkeepers.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":"2014-08-22T01:50:31.000Z","updated_at":"2023-02-02T14:01:41.000Z","dependencies_parsed_at":"2022-08-17T15:35:39.497Z","dependency_job_id":null,"html_url":"https://github.com/bkeepers/envy","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/bkeepers%2Fenvy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkeepers%2Fenvy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkeepers%2Fenvy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkeepers%2Fenvy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bkeepers","download_url":"https://codeload.github.com/bkeepers/envy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252562639,"owners_count":21768328,"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-10-02T23:21:39.669Z","updated_at":"2025-05-05T19:30:03.921Z","avatar_url":"https://github.com/bkeepers.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Envy\n\na schema describing and validating the environment variables needed by an application.\n\nWhy?\n\n1. All available configuration is explicitly defined, documented and easily inspectable.\n2. All configuration can be overridden by environment variables, conforming to the [Twelve-Factor App](http://12factor.net/config) methodology.\n3. The schema serves as documentation, and since it's executable and used by the application, will always be up to date.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"envy\", github: \"bkeepers/envy\"\n```\n\nAnd then execute:\n\n```\n$ bundle\n```\n\n## Usage\n\nCreate an `Envfile` in the root of your application.\n\n```ruby\ndesc \"Support email shown on the contact page.\"\nstring :support_email, default: \"support@example.com\"\n\ndesc \"The max duration (in seconds) a request can take before it times out.\"\ninteger :request_timeout, default: 10\n\ndesc \"Boolean attribute specifying whether the site is in SSL mode.\"\nboolean :ssl, default: Rails.env.production?\n```\n\nEnvy reads the schema when the application bootstraps and:\n\n1. Defines `$ENV` with reader methods for each variable that fetch values from `ENV`\n2. Validates required environment variables, raising an error if any are missing\n3. Casts values\n4. Sets `:default` values\n\nYou can access the environment through `$ENV`.\n\n```ruby\n# For example, in config/application.rb\nconfig.action_mailer.default_options = {\n  from: $ENV.support_email\n}\n\nconfig.force_ssl = $ENV.ssl?\n```\n\nVariables can be set in the environment at runtime using the variable name in `SCREAMING_SNAKE_CASE`:\n\n```\n$ REQUEST_TIMEOUT=30 rails server\n```\n\n### Manual setup\n\nSetup happens automatically in a Rails app. To use Envy outside of Rails, run:\n\n```ruby\nrequire 'envy'\n\n$ENV = Envy.environment.setup('Envfile')\n```\n\n## Types\n\nEnvy supports type casting of variable values.\n\n### `string`\n\n```ruby\nstring :support_email, default: \"support@example.com\"\n# \u003e\u003e $ENV.support_email\n# =\u003e \"support@example.com\"\n```\n\n### `boolean`\n\n```ruby\nboolean :ssl, default: true\n# \u003e\u003e $ENV.ssl?\n# =\u003e true\n```\n\n### `integer`\n\n```ruby\ninteger :request_timeout, default: 10\n# \u003e\u003e $ENV.request_timeout\n# =\u003e 10\n```\n\n### `decimal`\n\n```ruby\ndecimal :sample_rate, default: 0.1\n# \u003e\u003e $ENV.sample_rate\n# =\u003e 0.1\n```\n\n### `uri`\n\n```ruby\nuri :app_host, default: \"https://example.com\n# \u003e\u003e $ENV.app_host\n# =\u003e #\u003cAddressable::URI:0x1040 URI:https://example.com\u003e\n```\n\n### Custom types\n\nDeclare your own types by extending [`Envy::Type::Variable`](lib/envy/type/variable.rb) and implementing `#cast`.\n\n```ruby\nclass MyType \u003c Envy::Type::Variable\n  def cast(value)\n    # return cast value here\n  end\nend\n\ntype :my_type, MyType\n\ndesc \"My custom variable type\"\nmy_type :var_name\n```\n\n## Options\n\n### `:required`\n\nAll defined variables without a default value are required. When the `Envfile` is loaded, it will raise an exception if the required keys are not set.\n\n```\nMissing environment variables: ENCRYPTION_KEY\n```\n\nThe `:required` option can be set to `false` for optional values.\n\n```ruby\nstring :encryption_key, required: false\n```\n\n### `:default`\n\nThe `:default` can be used to set a default value when the variable is not defined in `ENV`.\n\n```ruby\ninteger :request_timeout, default: 10\n```\n\nIf logic is required to set a default, a lambda can be passed and it will be called if a variable is not set in `ENV`.\n\n```ruby\nboolean :check_for_internet_connection?, default: false\n\nboolean :online, default: -\u003e { check_for_internet_connection? ? Site.google_reachable? : true }\nend\n```\n\n### Transform block\n\nPass a block to a variable definition and it will be called to transform the value.\n\n```ruby\nstring :admin_ids do |value|\n  value.split(\",\").map(\u0026:to_i)\nend\n# \u003e\u003e ENV[\"ADMIN_IDS\"] = \"1,2,3\"\n# \u003e\u003e $ENVY.admin_ids\n# =\u003e [1, 2, 3]\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/bkeepers/envy/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkeepers%2Fenvy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbkeepers%2Fenvy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkeepers%2Fenvy/lists"}