Skip to content

Commit

Permalink
Launch!
Browse files Browse the repository at this point in the history
Ported from Crystal: <https://github.com/grottopress/envy>.
  • Loading branch information
akadusei committed Jun 1, 2024
0 parents commit 0d92d72
Show file tree
Hide file tree
Showing 21 changed files with 621 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test
on:
push:
paths:
- '**.rb'
- '.github/workflows/test.yml'
pull_request:
branches: [master]
paths:
- '**.rb'
- '.github/workflows/test.yml'
schedule:
- cron: '0 5 * * 6'
jobs:
checks:
strategy:
fail-fast: false
matrix:
ruby: ['3.0.0']
runs-on: ubuntu-latest
continue-on-error: false
steps:
- name: Download source
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Lint code
run: bundle exec rubocop
specs:
strategy:
fail-fast: false
matrix:
ruby: ['3.0.0', ruby, jruby, truffleruby]
experimental: [false]
include:
- ruby: head
experimental: true
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
steps:
- name: Download source
uses: actions/checkout@v4
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run tests
run: bundle exec rspec -w
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status

.ruby-version
Gemfile.lock
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
31 changes: 31 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable
TargetRubyVersion: 3.0

Lint/AssignmentInCondition:
Enabled: false

RSpec/ExampleLength:
Enabled: false

RSpec/HookArgument:
Enabled: false

RSpec/MultipleExpectations:
Enabled: false

Style/Documentation:
Enabled: false

Style/FetchEnvVar:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [Unreleased]

## [0.1.0] - 2024-05-31

- Initial release
16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec

group :development, :test do
gem "rake", "~> 13.0", require: false
gem "rubocop", "~> 1.21", require: false
gem "rubocop-rake", "~> 0.6.0", require: false
end

group :test do
gem "rspec", "~> 3.0"
gem "rubocop-rspec", "~> 2.29", require: false
end
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024-present GrottoPress <info@grottopress.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Envy

**Envy** loads and sets environment variables from YAML. It supports all YAML data types, including arrays and hashes.

*Envy* uses the YAML key mapping of a value as the environment variable name. For example, the following YAML configuration...

```yaml
---
app:
database:
host: localhost
port: 4321
server:
hosts:
- localhost
- grottopress.localhost
port: 8080
webhooks:
- url: "https://example.com"
token: "a1b2c2"
- url: "https://myapp.net"
token: "d4e5f6"
```
...sets environment variables as follows:
```ruby
ENV["APP_DATABASE_HOST"] = "localhost"
ENV["APP_DATABASE_PORT"] = "4321"

ENV["APP_SERVER_HOSTS_0"] = "localhost"
ENV["APP_SERVER_HOSTS_1"] = "grottopress.localhost"
ENV["APP_SERVER_PORT"] = "8080"

ENV["APP_WEBHOOKS_0_URL"] = "https://example.com"
ENV["APP_WEBHOOKS_0_TOKEN"] = "a1b2c2"
ENV["APP_WEBHOOKS_1_URL"] = "https://myapp.net"
ENV["APP_WEBHOOKS_1_TOKEN"] = "d4e5f6"
```

*Envy* loads environment variables only once per application life-cycle. This avoids the overhead of reading and parsing YAML files on every single request.

It sets file permission (`0600` by default) for all config files.

*Envy* supports loading a file from a supplied list of files in decreasing order of priority; the first readable file is loaded.

## Installation

Install the gem and add to the application's Gemfile by executing:

```
bundle add envy --git=https://github.com/GrottoPress/envy.rb
```

If bundler is not being used to manage dependencies, install the gem by executing:

```
# Clone repository
git clone https://github.com/GrottoPress/envy.rb.git ./envy
# Change to the envy directory
cd ./envy
# Build gem
gem build envy.gemspec -o envy.gem
# Install gem
gem install envy.gem
```

## Usage

- Load the first readable file from a supplied list of files. Optionally set files permissions. This does *not* overwrite existing environment variables:

```ruby
require "envy"

Envy.from_file ".env.yml", ".env.dev.yml", perm: 0o400
```

- Load the first readable file from a supplied list of files. Optionally set files permissions. This *overwrites* existing environment variables:

```ruby
require "envy"
Envy.from_file! ".env.yml", ".env.dev.yml", perm: 0o400
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

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).

## Contributing

1. [Fork it](https://github.com/GrottoPress/envy.rb/fork)
1. Switch to the `master` branch: `git checkout master`
1. Create your feature branch: `git checkout -b my-new-feature`
1. Make your changes, updating changelog and documentation as appropriate.
1. Commit your changes: `git commit`
1. Push to the branch: `git push origin my-new-feature`
1. Submit a new *Pull Request* against the `GrottoPress:master` branch.
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

RSpec::Core::RakeTask.new(:spec)

RuboCop::RakeTask.new do |task|
task.requires << "rubocop-rake"
end

task default: %i[spec rubocop]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "envy"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
31 changes: 31 additions & 0 deletions envy.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative "lib/envy/version"

Gem::Specification.new do |spec|
spec.name = "envy"
spec.version = Envy::VERSION
spec.authors = ["akadusei"]
spec.email = ["attakusiadusei@gmail.com"]

spec.summary = "Load environment variables from YAML"
spec.homepage = "https://github.com/GrottoPress/envy.rb"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.0.0"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["rubygems_mfa_required"] = "true"
spec.metadata["source_code_uri"] = "https://github.com/GrottoPress/envy.rb"

spec.files = Dir["lib/**/*.rb"] + ["LICENSE"]

spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
end
Loading

0 comments on commit 0d92d72

Please sign in to comment.