Repository: puma/puma
File: lib/puma/configuration.rb (Ruby)

Code before:
      @_options = @_options.flatten
      self
    end

    def puma_default_options(env = ENV)
      defaults = DEFAULTS.dup
      puma_options_from_env(env).each { |k,v| defaults[k] = v if v }
      defaults
    end

    def puma_options_from_env(env = ENV)
      min = env['PUMA_MIN_THREADS'] || env['MIN_THREADS']
      max = env['PUMA_MAX_THREADS'] || env['MAX_THREADS']
      persistent_timeout = env['PUMA_PERSISTENT_TIMEOUT']
      workers = if env['WEB_CONCURRENCY'] == 'auto'
        require_processor_counter
        ::Concurrent.available_processor_count
      else
        env['WEB_CONCURRENCY']
      end

      {
        min_threads: min && min != "" && Integer(min),
        max_threads: max && max != "" && Integer(max),
        persistent_timeout: persistent_timeout && persistent_timeout != "" && Integer(persistent_timeout),
        workers: workers && workers.strip != "" && Integer(workers),
        environment: env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'],
      }
    end

    def load
      @loaded = true
      config_files.each { |config_file| @file_dsl._load_from(config_file) }
      @_options
    end

    def config_files
      raise NotLoadedError, "ensure load is called before accessing config_files" unless @loaded

      files = @_options.all_of(:config_files)

      return [] if files == ['-']
      return files if files.any?

      first_default_file = %W(config/puma/#{@_options[:environment]}.rb config/puma.rb).find do |f|
        File.exist?(f)
      end

      [first_default_file]
    end


Review comment (suggestion):
another option is

```ruby
workers: !workers&.empty? && Integer(workers),
```

Code after:
      @_options = @_options.flatten
      self
    end

    def puma_default_options(env = ENV)
      defaults = DEFAULTS.dup
      puma_options_from_env(env).each { |k,v| defaults[k] = v if v }
      defaults
    end

    def puma_options_from_env(env = ENV)
      min = env['PUMA_MIN_THREADS'] || env['MIN_THREADS']
      max = env['PUMA_MAX_THREADS'] || env['MAX_THREADS']
      persistent_timeout = env['PUMA_PERSISTENT_TIMEOUT']
      workers = if env['WEB_CONCURRENCY'] == 'auto'
        require_processor_counter
        ::Concurrent.available_processor_count
      else
        env['WEB_CONCURRENCY']&.strip
      end

      {
        min_threads: min && min != "" && Integer(min),
        max_threads: max && max != "" && Integer(max),
        persistent_timeout: persistent_timeout && persistent_timeout != "" && Integer(persistent_timeout),
        workers: workers && workers != "" && Integer(workers),
        environment: env['APP_ENV'] || env['RACK_ENV'] || env['RAILS_ENV'],
      }
    end

    def load
      @loaded = true
      config_files.each { |config_file| @file_dsl._load_from(config_file) }
      @_options
    end

    def config_files
      raise NotLoadedError, "ensure load is called before accessing config_files" unless @loaded

      files = @_options.all_of(:config_files)

      return [] if files == ['-']
      return files if files.any?

      first_default_file = %W(config/puma/#{@_options[:environment]}.rb config/puma.rb).find do |f|
        File.exist?(f)
      end

      [first_default_file]
    end