Sha256: 3dc6ae409e0c04e954f7831af6768edcea3d6a4acb185550bdb6bf69531a230f

Contents?: true

Size: 453 Bytes

Versions: 30

Compression:

Stored size: 453 Bytes

Contents

# frozen_string_literal: true

module EnvSettings
  def env_prefix(new_prefix = nil)
    @env_prefix = new_prefix if new_prefix
    @env_prefix
  end

  def from_env(*method_names)
    builder = Sinclair.new(self)

    method_names.each do |method_name|
      env_key = [env_prefix, method_name].compact.join('_').upcase

      builder.add_class_method(method_name, cached: true) do
        ENV[env_key]
      end

      builder.build
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/support/models/env_settings.rb
sinclair-2.1.0 spec/support/models/env_settings.rb
sinclair-2.0.1 spec/support/models/env_settings.rb
sinclair-2.0.0 spec/support/models/env_settings.rb
sinclair-1.16.3 spec/support/models/env_settings.rb
sinclair-1.16.2 spec/support/models/env_settings.rb
sinclair-1.16.1 spec/support/models/env_settings.rb
sinclair-1.16.0 spec/support/models/env_settings.rb
sinclair-1.15.0 spec/support/models/env_settings.rb
sinclair-1.14.2 spec/support/models/env_settings.rb
sinclair-1.14.1 spec/support/models/env_settings.rb
sinclair-1.14.0 spec/support/models/env_settings.rb
sinclair-1.13.0 spec/support/models/env_settings.rb
sinclair-1.12.1 spec/support/models/env_settings.rb
sinclair-1.12.0 spec/support/models/env_settings.rb
sinclair-1.11.0 spec/support/models/env_settings.rb
sinclair-1.10.0 spec/support/models/env_settings.rb
sinclair-1.9.0 spec/support/models/env_settings.rb
sinclair-1.8.0 spec/support/models/env_settings.rb
sinclair-1.7.0 spec/support/models/env_settings.rb