Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for dotenv-rails #436

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@
[submodule "gems/recaptcha/5.15/_src"]
path = gems/recaptcha/5.15/_src
url = https://github.com/ambethia/recaptcha.git
[submodule "gems/dotenv-rails/2.8/_src"]
path = gems/dotenv-rails/2.8/_src
url = https://github.com/bkeepers/dotenv.git
[submodule "gems/activerecord-import/1.5/_src"]
path = gems/activerecord-import/1.5/_src
url = https://github.com/zdennis/activerecord-import.git
Expand Down
21 changes: 21 additions & 0 deletions gems/dotenv-rails/2.8/_scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting.
set -eou pipefail
# Internal Field Separator - Linux shell variable
IFS=$'\n\t'
# Print shell input lines
set -v

# Set RBS_DIR variable to change directory to execute type checks using `steep check`
RBS_DIR=$(cd $(dirname $0)/..; pwd)
# Set REPO_DIR variable to validate RBS files added to the corresponding folder
REPO_DIR=$(cd $(dirname $0)/../../..; pwd)
# Validate RBS files, using the bundler environment present
bundle exec rbs --repo $REPO_DIR -r dotenv-rails:2.8 validate --silent

cd ${RBS_DIR}/_test
# Run type checks
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
1 change: 1 addition & 0 deletions gems/dotenv-rails/2.8/_src
Submodule _src added at 45b712
11 changes: 11 additions & 0 deletions gems/dotenv-rails/2.8/_test/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
D = Steep::Diagnostic

target :test do
check "."
signature "."

repo_path "../../../"
library "dotenv-rails"

configure_code_diagnostics(D::Ruby.all_error)
end
1 change: 1 addition & 0 deletions gems/dotenv-rails/2.8/_test/env_files/file1.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KEY1=key1
2 changes: 2 additions & 0 deletions gems/dotenv-rails/2.8/_test/env_files/file2.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KEY1=key1-hoge
KEY2=key2
18 changes: 18 additions & 0 deletions gems/dotenv-rails/2.8/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Write Ruby code to test the RBS.
# It is type checked by `steep check` command.

require 'dotenv'

Dotenv.load
Dotenv.load('./env_files/file1.env', './env_files/file2.env')
Dotenv.load('./env_files/file3.env')

Dotenv.load!
Dotenv.load!('./env_files/file1.env', './env_files/file2.env')

Dotenv.require_keys('KEY1', 'KEY2')

pp Dotenv.parse('./env_files/file1.env', './env_files/file2.env')['KEY1']

Dotenv.overload('./env_files/file1.env', './env_files/file2.env')
Dotenv.overload!('./env_files/file1.env', './env_files/file2.env')
21 changes: 21 additions & 0 deletions gems/dotenv-rails/2.8/dotenv-rails.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Dotenv
def self.load: (*String filenames) -> void
| () -> void
def self.load!: (*String filenames) -> void
| () -> void

def self.require_keys: (*String keys) -> void
def self.parse: (*String filenames) -> Environment

def self.overload: (*String filenames) -> void
| () -> void
def self.overload!: (*String filenames) -> void
| () -> void

class Environment < Hash[String, untyped]
attr_reader filename: String

def initialize: (String filename, boolish is_load) -> void
def load: (boolish is_load) -> self
end
end