module LapisLazuli::WorldModule::Variable

Module for variable replacement

Manages the following:

scenario   - for per-scenario variables
uuid       - for the entire test run
time       - for the entire test run
storage    - for the entire test run
versions   - versions as gathered by e.g. fetch_versions

Private Class Methods

destroy(world) click to toggle source
# File lib/lapis_lazuli/world/variable.rb, line 130
def self.destroy(world)
  Proc.new do |w|
    if world.has_storage?
      world.storage.destroy(world)
    end
  end
end

Public Instance Methods

has_storage?() click to toggle source

Storage “singleton”

# File lib/lapis_lazuli/world/variable.rb, line 65
def has_storage?
  b = Runtime.instance.get :variable_data
  return !b[:storage].nil?
end
scenario() click to toggle source

Scenario “singleton”

# File lib/lapis_lazuli/world/variable.rb, line 35
def scenario
  return data(:scenario) do
    Scenario.new
  end
end
storage() click to toggle source
# File lib/lapis_lazuli/world/variable.rb, line 70
def storage
  return data(:storage) do
    storage = Storage.new
    storage.set("time", time)
    storage.set("uuid", uuid)

    storage
  end
end
time() click to toggle source

Time “singleton”

# File lib/lapis_lazuli/world/variable.rb, line 43
def time
  return data(:time) do
    time = Time.now
    @time = {
      :timestamp => time.strftime('%y%m%d_%H%M%S'),
      :iso_timestamp => time.utc.strftime("%FT%TZ"),
      :iso_short => time.utc.strftime("%y%m%dT%H%M%SZ"),
      :epoch => time.to_i.to_s
    }
  end
end
uuid() click to toggle source

UUID “singleton”

# File lib/lapis_lazuli/world/variable.rb, line 57
def uuid
  return data(:uuid) do
    SecureRandom.hex
  end
end
variable(string) click to toggle source

Update the variable with timestamps

# File lib/lapis_lazuli/world/variable.rb, line 83
def variable(string)
  init

  email_domain = "spriteymail.net"
  if has_env_or_config?("email_domain")
    email_domain = env_or_config("email_domain")
  end
  random_uuid = SecureRandom.hex

  # Prepare current values.
  values = {}
  LapisLazuli::PLACEHOLDERS.each do |placeholder, value|
    values[placeholder] = eval value[0]
  end

  return string % values
end
variable!(string) click to toggle source

Same as variable, but modify the string.

# File lib/lapis_lazuli/world/variable.rb, line 103
def variable!(string)
  string.replace(variable(string))
end

Private Instance Methods

data(name, &block) click to toggle source
# File lib/lapis_lazuli/world/variable.rb, line 109
def data(name, &block)
  d = Runtime.instance.get :variable_data
  if not d.nil?
    if not d.is_a? Hash
      raise "Expect a hash for variables managed by the Variable module"
    end
  else
    d = {}
  end

  if not d.has_key? name
    value = block.call()
    d[name] = value

    Runtime.instance.set(self, :variable_data, d, Variable.destroy(self))
  end

  return d[name]
end