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

fix: processing arrays for required except #156

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

dominikb
Copy link
Contributor

What is the purpose of this pull request?

The documented feature of allowing arrays for the env: { except: } option is broken.

Reproducible example

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  gem 'anyway_config'
end

class MyConfig < Anyway::Config
  attr_config :user

  required :user, env: { except: [ 'test' ] }
end

Anyway::Settings.current_environment = 'test'

puts "Environment: #{Anyway::Settings.current_environment}"
[
  "Anyway::Settings.matching_env?('test')           # (true expected) ",
  "Anyway::Settings.matching_env?({except: 'test'}) # (false expected)",
  "Anyway::Settings.matching_env?(except: ['test']) # (false expected)",
].each { |example| puts("#{example} => #{eval(example)}")}

begin
  MyConfig.new
rescue StandardError => e
  puts e
end

Output

Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Environment: test
Anyway::Settings.matching_env?('test')           # (true expected)  => true
Anyway::Settings.matching_env?({except: 'test'}) # (false expected) => false
Anyway::Settings.matching_env?(except: ['test']) # (false expected) => true
The following config parameters for `MyConfig(config_name: my)` are missing or empty: user

What changes did you make? (overview)

Is there anything you'd like reviewers to focus on?

Checklist

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation

Nesting arrays would yield convert an Array to a String before matching it against the current environment and always fail.
@palkan
Copy link
Owner

palkan commented Feb 12, 2025

Thanks!

@palkan palkan merged commit c6ad3eb into palkan:master Feb 12, 2025
14 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants