Module: LapisLazuli::WorldModule::Variable
Overview
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
Instance Method Summary collapse
-
#has_storage? ⇒ Boolean
Storage “singleton”.
-
#scenario ⇒ Object
Scenario “singleton”.
- #storage ⇒ Object
-
#time ⇒ Object
Time “singleton”.
-
#uuid ⇒ Object
UUID “singleton”.
-
#variable(string) ⇒ Object
Update the variable with timestamps.
-
#variable!(string) ⇒ Object
Same as variable, but modify the string.
Methods included from Config
#config, #current_env, #env, #env_or_config, #has_config?, #has_env?, #has_env_or_config?, #init, #load_config, #load_config_from_file, #var_from_env
Methods included from Config::ClassMethods
Instance Method Details
#has_storage? ⇒ Boolean
Storage “singleton”
65 66 67 68 |
# File 'lib/lapis_lazuli/world/variable.rb', line 65 def has_storage? b = Runtime.instance.get :variable_data return !b[:storage].nil? end |
#scenario ⇒ Object
Scenario “singleton”
35 36 37 38 39 |
# File 'lib/lapis_lazuli/world/variable.rb', line 35 def scenario return data(:scenario) do Scenario.new end end |
#storage ⇒ Object
70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
Time “singleton”
43 44 45 46 47 48 49 50 51 52 53 |
# 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 ⇒ Object
UUID “singleton”
57 58 59 60 61 |
# File 'lib/lapis_lazuli/world/variable.rb', line 57 def uuid return data(:uuid) do SecureRandom.hex end end |
#variable(string) ⇒ Object
Update the variable with timestamps
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
Same as variable, but modify the string.
103 104 105 |
# File 'lib/lapis_lazuli/world/variable.rb', line 103 def variable!(string) string.replace(variable(string)) end |