env_guard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 91ea22fb0d04c2fa674916b3c0c735c2e273f328582bd40ef29b2c895c722d1c
4
+ data.tar.gz: af79746f592ba593ed7331de38829d4bcf51f8687ece40a2a24ebb34373d6ede
5
+ SHA512:
6
+ metadata.gz: fcd2584c7804d191b9d7b6afe8f697913c7b7a8b9b0a50abd7617e362acd869b8f67c437ead004d1c461e11ea7e102a17d487723dbc17c47aa53107e6d5001ed
7
+ data.tar.gz: 600251f0af05e969e44f557213df171104dc947ae07a70b5101c3932d9a70e719c8cdd67871193798e1249a83da21a335d95fa9838a0f77b17ee473b461112d6
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ['3.3.9']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby-version }}
24
+ bundler-cache: true
25
+
26
+ - name: Run RSpec
27
+ run: bundle exec rake spec
28
+
29
+ - name: Run RuboCop
30
+ run: bundle exec rake rubocop
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.3
3
+ Exclude:
4
+ - 'vendor/**/*'
5
+ - 'bin/**/*'
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Layout/LineLength:
11
+ Max: 100
12
+
13
+ Metrics/MethodLength:
14
+ Max: 15
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'spec/**/*'
19
+ - 'env_guard.gemspec'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.9
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.10
7
+ before_install: gem install bundler -v 1.17.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial gem release with environment variable validation
12
+
13
+ ### Changed
14
+
15
+ ### Deprecated
16
+
17
+ ### Removed
18
+
19
+ ### Fixed
20
+
21
+ ### Security
22
+
23
+ ## [0.1.0] - 2026-01-26
24
+
25
+ ### Added
26
+ - `EnvGuard.check!` method to validate required environment variables
27
+ - Support for checking multiple environment variables at once
28
+ - `MissingEnvError` exception for missing variables
29
+ - RSpec test suite
30
+ - RuboCop linting configuration
31
+ - GitHub Actions CI workflow
32
+
33
+ [Unreleased]: https://github.com/punavwalke/env_guard/compare/v0.1.0...HEAD
34
+ [0.1.0]: https://github.com/punavwalke/env_guard/releases/tag/v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ ruby "3.3.9"
6
+
7
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
+
9
+ # Specify your gem's dependencies in env_guard.gemspec
10
+ gemspec
11
+
12
+ group :development do
13
+ gem "rubocop", "~> 1.50"
14
+ gem "rubocop-rspec", "~> 2.20"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ env_guard (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.3)
10
+ diff-lcs (1.6.2)
11
+ json (2.18.0)
12
+ language_server-protocol (3.17.0.5)
13
+ lint_roller (1.1.0)
14
+ parallel (1.27.0)
15
+ parser (3.3.10.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ prism (1.8.0)
19
+ racc (1.8.1)
20
+ rainbow (3.1.1)
21
+ rake (13.3.1)
22
+ regexp_parser (2.11.3)
23
+ rspec (3.13.2)
24
+ rspec-core (~> 3.13.0)
25
+ rspec-expectations (~> 3.13.0)
26
+ rspec-mocks (~> 3.13.0)
27
+ rspec-core (3.13.6)
28
+ rspec-support (~> 3.13.0)
29
+ rspec-expectations (3.13.5)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-mocks (3.13.7)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-support (3.13.6)
36
+ rubocop (1.82.1)
37
+ json (~> 2.3)
38
+ language_server-protocol (~> 3.17.0.2)
39
+ lint_roller (~> 1.1.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.3.0.2)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 2.9.3, < 3.0)
44
+ rubocop-ast (>= 1.48.0, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 4.0)
47
+ rubocop-ast (1.49.0)
48
+ parser (>= 3.3.7.2)
49
+ prism (~> 1.7)
50
+ rubocop-capybara (2.22.1)
51
+ lint_roller (~> 1.1)
52
+ rubocop (~> 1.72, >= 1.72.1)
53
+ rubocop-factory_bot (2.28.0)
54
+ lint_roller (~> 1.1)
55
+ rubocop (~> 1.72, >= 1.72.1)
56
+ rubocop-rspec (2.31.0)
57
+ rubocop (~> 1.40)
58
+ rubocop-capybara (~> 2.17)
59
+ rubocop-factory_bot (~> 2.22)
60
+ rubocop-rspec_rails (~> 2.28)
61
+ rubocop-rspec_rails (2.29.1)
62
+ rubocop (~> 1.61)
63
+ ruby-progressbar (1.13.0)
64
+ unicode-display_width (3.2.0)
65
+ unicode-emoji (~> 4.1)
66
+ unicode-emoji (4.2.0)
67
+
68
+ PLATFORMS
69
+ arm64-darwin-24
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (>= 2.0)
74
+ env_guard!
75
+ rake (~> 13.0)
76
+ rspec (~> 3.0)
77
+ rubocop (~> 1.50)
78
+ rubocop-rspec (~> 2.20)
79
+
80
+ RUBY VERSION
81
+ ruby 3.3.9p170
82
+
83
+ BUNDLED WITH
84
+ 2.5.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 TODO: Write your name
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,58 @@
1
+ # EnvGuard
2
+
3
+ A lightweight Ruby gem that validates and guards your required environment variables. Ensures your application has all necessary environment variables configured before startup.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'env_guard'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install env_guard
20
+
21
+ ## Usage
22
+
23
+ Add `EnvGuard.check!` to your application startup to validate required environment variables:
24
+
25
+ ```ruby
26
+ # In your application initialization (e.g., config/application.rb)
27
+ require 'env_guard'
28
+
29
+ EnvGuard.check!(:DATABASE_URL, :API_KEY, :SECRET_TOKEN)
30
+ ```
31
+
32
+ If any required variables are missing or empty, EnvGuard raises a `MissingEnvError`:
33
+
34
+ ```ruby
35
+ EnvGuard.check!(:DATABASE_URL, :API_KEY)
36
+ # Raises: EnvGuard::MissingEnvError: Missing ENV variables: DATABASE_URL, API_KEY
37
+ ```
38
+
39
+ You can also pass variables as an array:
40
+
41
+ ```ruby
42
+ required_vars = [:DATABASE_URL, :API_KEY, :SECRET_TOKEN]
43
+ EnvGuard.check!(required_vars)
44
+ ```
45
+
46
+ ## Development
47
+
48
+ 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.
49
+
50
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/punavwalke/env_guard.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new(:rubocop)
9
+
10
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "env_guard"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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
data/env_guard.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "env_guard/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "env_guard"
9
+ spec.version = EnvGuard::VERSION
10
+ spec.authors = ["Punav Walke"]
11
+ spec.email = ["punavw17@gmail.com"]
12
+
13
+ spec.summary = "A gem to guard environment variables"
14
+ spec.description = "A gem to guard environment variables"
15
+ spec.homepage = "https://github.com/punavwalke/env_guard"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/punavwalke/env_guard"
25
+ spec.metadata["changelog_uri"] = "https://github.com/yourusername/env_guard/blob/main/CHANGELOG.md"
26
+ else
27
+ raise "RubyGems 2.0 or newer is required to protect against " \
28
+ "public gem pushes."
29
+ end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
36
+ spec.bindir = "exe"
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.required_ruby_version = ">= 3.3"
41
+
42
+ spec.add_development_dependency "bundler", ">= 2.0"
43
+ spec.add_development_dependency "rake", "~> 13.0"
44
+ spec.add_development_dependency "rspec", "~> 3.0"
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvGuard
4
+ VERSION = "0.1.0"
5
+ end
data/lib/env_guard.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "env_guard/version"
4
+
5
+ # EnvGuard module provides utilities to guard and validate environment variables
6
+ module EnvGuard
7
+ class MissingEnvError < StandardError; end
8
+
9
+ def self.hello
10
+ puts "Env Guard Loaded"
11
+ end
12
+
13
+ def self.check!(*vars, required: nil, optional: []) # rubocop:disable Lint/UnusedMethodArgument
14
+ required_vars = normalize_vars(vars.any? ? vars : required)
15
+ missing = find_missing_vars(required_vars)
16
+
17
+ return if missing.empty?
18
+
19
+ raise MissingEnvError, "Missing ENV variables: #{missing.join(', ')}"
20
+ end
21
+
22
+ class << self
23
+ private
24
+
25
+ def normalize_vars(vars)
26
+ Array(vars).flatten.map(&:to_s)
27
+ end
28
+
29
+ def find_missing_vars(vars)
30
+ vars.select { |var| ENV[var].nil? || ENV[var].empty? }
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_guard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Punav Walke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A gem to guard environment variables
56
+ email:
57
+ - punavw17@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/ci.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".ruby-version"
67
+ - ".travis.yml"
68
+ - CHANGELOG.md
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - env_guard.gemspec
77
+ - lib/env_guard.rb
78
+ - lib/env_guard/version.rb
79
+ homepage: https://github.com/punavwalke/env_guard
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ allowed_push_host: https://rubygems.org
84
+ homepage_uri: https://github.com/punavwalke/env_guard
85
+ source_code_uri: https://github.com/punavwalke/env_guard
86
+ changelog_uri: https://github.com/yourusername/env_guard/blob/main/CHANGELOG.md
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '3.3'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.5.22
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A gem to guard environment variables
106
+ test_files: []