Class: SpecForge::Attribute::Environment

Inherits:
Attribute
  • Object
show all
Defined in:
lib/spec_forge/attribute/environment.rb

Overview

Represents an attribute that retrieves its value from an environment variable. This allows specs to reference environment variables dynamically.

Examples:

Basic usage in YAML

api_key: "{{ env.API_KEY }}"
database_url: "{{ env.DATABASE_URL }}"
secret: "{{ env.MY_SECRET_TOKEN }}"

Constant Summary collapse

KEYWORD_REGEX =

Regular expression pattern that matches attribute keywords with this prefix. Used for identifying this attribute type during parsing. Matches case-insensitively (env., ENV., Env., etc.)

Returns:

  • (Regexp)
/^env\./i

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Creates a new environment attribute by extracting the variable name

Parameters:

  • input (String)

    The environment variable reference (e.g., "env.API_KEY")



29
30
31
32
33
# File 'lib/spec_forge/attribute/environment.rb', line 29

def initialize(...)
  super

  @variable_name = input.sub(KEYWORD_REGEX, "")
end

Instance Method Details

#valueString?

Returns the value of the referenced environment variable

Returns:

  • (String, nil)

    The environment variable value, or nil if not set



40
41
42
# File 'lib/spec_forge/attribute/environment.rb', line 40

def value
  ENV[@variable_name]
end