Class: KnapsackPro::Config::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/config/env.rb

Constant Summary collapse

LOG_LEVELS =
{
  'fatal'  => ::Logger::FATAL,
  'error'  => ::Logger::ERROR,
  'warn'  => ::Logger::WARN,
  'info'  => ::Logger::INFO,
  'debug' => ::Logger::DEBUG,
}

Class Method Summary collapse

Class Method Details

.branchObject



50
51
52
# File 'lib/knapsack_pro/config/env.rb', line 50

def branch
  env_for('KNAPSACK_PRO_BRANCH', :branch)
end

.branch_encryptedObject



140
141
142
# File 'lib/knapsack_pro/config/env.rb', line 140

def branch_encrypted
  ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED']
end

.branch_encrypted?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/knapsack_pro/config/env.rb', line 144

def branch_encrypted?
  branch_encrypted == 'true'
end

.ci?Boolean

Returns:

  • (Boolean)


275
276
277
278
# File 'lib/knapsack_pro/config/env.rb', line 275

def ci?
  ENV.fetch('CI', 'false').downcase == 'true' ||
    detected_ci != KnapsackPro::Config::CI::Base
end

.ci_node_build_idObject



29
30
31
32
33
# File 'lib/knapsack_pro/config/env.rb', line 29

def ci_node_build_id
  env_name = 'KNAPSACK_PRO_CI_NODE_BUILD_ID'
  env_for(env_name, :node_build_id) ||
    raise("Missing environment variable #{env_name}. Read more at #{KnapsackPro::Urls::KNAPSACK_PRO_CI_NODE_BUILD_ID}")
end

.ci_node_indexObject



22
23
24
25
26
27
# File 'lib/knapsack_pro/config/env.rb', line 22

def ci_node_index
  env_name = 'KNAPSACK_PRO_CI_NODE_INDEX'
  env_value = env_for(env_name, :node_index)

  env_value ? env_value.to_i : raise_missing_env_for(env_name)
end

.ci_node_retry_countObject



35
36
37
# File 'lib/knapsack_pro/config/env.rb', line 35

def ci_node_retry_count
  (env_for('KNAPSACK_PRO_CI_NODE_RETRY_COUNT', :node_retry_count) || 0).to_i
end

.ci_node_totalObject



15
16
17
18
19
20
# File 'lib/knapsack_pro/config/env.rb', line 15

def ci_node_total
  env_name = 'KNAPSACK_PRO_CI_NODE_TOTAL'
  env_value = env_for(env_name, :node_total)

  env_value ? env_value.to_i : raise_missing_env_for(env_name)
end

.ci_providerObject



255
256
257
# File 'lib/knapsack_pro/config/env.rb', line 255

def ci_provider
  detected_ci.new.ci_provider
end

.commit_hashObject



46
47
48
# File 'lib/knapsack_pro/config/env.rb', line 46

def commit_hash
  env_for('KNAPSACK_PRO_COMMIT_HASH', :commit_hash)
end

.cucumber_queue_prefixObject



193
194
195
# File 'lib/knapsack_pro/config/env.rb', line 193

def cucumber_queue_prefix
  ENV.fetch('KNAPSACK_PRO_CUCUMBER_QUEUE_PREFIX', 'bundle exec')
end

.detected_ciObject



245
246
247
248
249
250
251
252
253
# File 'lib/knapsack_pro/config/env.rb', line 245

def detected_ci
  detected = KnapsackPro::Config::CI.constants.map do |constant|
    Object.const_get("KnapsackPro::Config::CI::#{constant}").new.detected
  end
    .compact
    .first

  detected || KnapsackPro::Config::CI::Base
end

.endpointObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/knapsack_pro/config/env.rb', line 152

def endpoint
  env_name = 'KNAPSACK_PRO_ENDPOINT'
  return ENV[env_name] if ENV[env_name]

  case mode
  when :development
    'http://api.knapsackpro.test:3000'
  when :test
    'https://api-staging.knapsackpro.com'
  when :production
    'https://api.knapsackpro.com'
  else
    required_env(env_name)
  end
end

.fallback_mode_enabledObject



124
125
126
# File 'lib/knapsack_pro/config/env.rb', line 124

def fallback_mode_enabled
  ENV.fetch('KNAPSACK_PRO_FALLBACK_MODE_ENABLED', true)
end

.fallback_mode_enabled?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/knapsack_pro/config/env.rb', line 128

def fallback_mode_enabled?
  fallback_mode_enabled.to_s == 'true'
end

.fixed_queue_splitObject



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/knapsack_pro/config/env.rb', line 176

def fixed_queue_split
  @fixed_queue_split ||= begin
    env_name = 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT'
    computed = env_for(env_name, :fixed_queue_split).to_s

    if !ENV.key?(env_name)
      KnapsackPro.logger.info("#{env_name} is not set. Using default value: #{computed}. Learn more at #{KnapsackPro::Urls::FIXED_QUEUE_SPLIT}")
    end

    computed
  end
end

.fixed_queue_split?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/knapsack_pro/config/env.rb', line 189

def fixed_queue_split?
  fixed_queue_split.to_s == 'true'
end

.fixed_test_suite_splitObject



168
169
170
# File 'lib/knapsack_pro/config/env.rb', line 168

def fixed_test_suite_split
  ENV.fetch('KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT', true)
end

.fixed_test_suite_split?Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/knapsack_pro/config/env.rb', line 172

def fixed_test_suite_split?
  fixed_test_suite_split.to_s == 'true'
end

.log_dirObject



263
264
265
# File 'lib/knapsack_pro/config/env.rb', line 263

def log_dir
  ENV['KNAPSACK_PRO_LOG_DIR']
end

.log_levelObject



259
260
261
# File 'lib/knapsack_pro/config/env.rb', line 259

def log_level
  LOG_LEVELS[ENV['KNAPSACK_PRO_LOG_LEVEL'].to_s.downcase] || ::Logger::INFO
end

.masked_user_seatObject



62
63
64
65
66
# File 'lib/knapsack_pro/config/env.rb', line 62

def masked_user_seat
  return unless user_seat

  KnapsackPro::MaskString.call(user_seat)
end

.max_request_retriesObject



39
40
41
42
43
44
# File 'lib/knapsack_pro/config/env.rb', line 39

def max_request_retries
  number = ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES']
  if number
    number.to_i
  end
end

.modeObject



234
235
236
237
238
239
240
241
242
243
# File 'lib/knapsack_pro/config/env.rb', line 234

def mode
  mode = ENV['KNAPSACK_PRO_MODE']
  return :production if mode.nil?
  mode = mode.to_sym
  if [:development, :test, :production].include?(mode)
    mode
  else
    raise ArgumentError.new('Wrong mode name')
  end
end

.project_dirObject



54
55
56
# File 'lib/knapsack_pro/config/env.rb', line 54

def project_dir
  env_for('KNAPSACK_PRO_PROJECT_DIR', :project_dir)
end

.queue_idObject



116
117
118
# File 'lib/knapsack_pro/config/env.rb', line 116

def queue_id
  ENV['KNAPSACK_PRO_QUEUE_ID'] || raise('Missing Queue ID')
end

.queue_recording_enabledObject



108
109
110
# File 'lib/knapsack_pro/config/env.rb', line 108

def queue_recording_enabled
  ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED']
end

.queue_recording_enabled?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/knapsack_pro/config/env.rb', line 112

def queue_recording_enabled?
  queue_recording_enabled == 'true'
end

.recording_enabledObject



96
97
98
# File 'lib/knapsack_pro/config/env.rb', line 96

def recording_enabled
  ENV['KNAPSACK_PRO_RECORDING_ENABLED']
end

.recording_enabled?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/knapsack_pro/config/env.rb', line 100

def recording_enabled?
  recording_enabled == 'true'
end

.regular_mode?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/knapsack_pro/config/env.rb', line 104

def regular_mode?
  recording_enabled?
end

.repository_adapterObject



92
93
94
# File 'lib/knapsack_pro/config/env.rb', line 92

def repository_adapter
  ENV['KNAPSACK_PRO_REPOSITORY_ADAPTER']
end

.rspec_split_by_test_examplesObject



197
198
199
# File 'lib/knapsack_pro/config/env.rb', line 197

def rspec_split_by_test_examples
  ENV.fetch('KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES', false)
end

.rspec_split_by_test_examples?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/knapsack_pro/config/env.rb', line 201

def rspec_split_by_test_examples?
  rspec_split_by_test_examples.to_s == 'true'
end

.rspec_test_example_detector_prefixObject



205
206
207
# File 'lib/knapsack_pro/config/env.rb', line 205

def rspec_test_example_detector_prefix
  ENV.fetch('KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX', 'bundle exec')
end

.saltObject



148
149
150
# File 'lib/knapsack_pro/config/env.rb', line 148

def salt
  required_env('KNAPSACK_PRO_SALT')
end

.set_test_runner_adapter(adapter_class) ⇒ Object



271
272
273
# File 'lib/knapsack_pro/config/env.rb', line 271

def set_test_runner_adapter(adapter_class)
  ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] = adapter_class.to_s.split('::').last
end

.slow_test_file_patternObject



72
73
74
# File 'lib/knapsack_pro/config/env.rb', line 72

def slow_test_file_pattern
  ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN']
end

.subset_queue_idObject



120
121
122
# File 'lib/knapsack_pro/config/env.rb', line 120

def subset_queue_id
  ENV['KNAPSACK_PRO_SUBSET_QUEUE_ID'] || raise('Missing Subset Queue ID')
end

.test_dirObject



88
89
90
# File 'lib/knapsack_pro/config/env.rb', line 88

def test_dir
  ENV['KNAPSACK_PRO_TEST_DIR']
end

.test_file_exclude_patternObject



76
77
78
# File 'lib/knapsack_pro/config/env.rb', line 76

def test_file_exclude_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN']
end

.test_file_listObject



80
81
82
# File 'lib/knapsack_pro/config/env.rb', line 80

def test_file_list
  ENV['KNAPSACK_PRO_TEST_FILE_LIST']
end

.test_file_list_source_fileObject



84
85
86
# File 'lib/knapsack_pro/config/env.rb', line 84

def test_file_list_source_file
  ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE']
end

.test_file_patternObject



68
69
70
# File 'lib/knapsack_pro/config/env.rb', line 68

def test_file_pattern
  ENV['KNAPSACK_PRO_TEST_FILE_PATTERN']
end

.test_files_encryptedObject



132
133
134
# File 'lib/knapsack_pro/config/env.rb', line 132

def test_files_encrypted
  ENV['KNAPSACK_PRO_TEST_FILES_ENCRYPTED']
end

.test_files_encrypted?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/knapsack_pro/config/env.rb', line 136

def test_files_encrypted?
  test_files_encrypted == 'true'
end

.test_runner_adapterObject



267
268
269
# File 'lib/knapsack_pro/config/env.rb', line 267

def test_runner_adapter
  ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER']
end

.test_suite_tokenObject



209
210
211
212
# File 'lib/knapsack_pro/config/env.rb', line 209

def test_suite_token
  env_name = 'KNAPSACK_PRO_TEST_SUITE_TOKEN'
  ENV[env_name] || raise("Missing environment variable #{env_name}. You should set environment variable like #{env_name}_RSPEC (note there is suffix _RSPEC at the end). knapsack_pro gem will set #{env_name} based on #{env_name}_RSPEC value. If you use other test runner than RSpec then use proper suffix.")
end

.test_suite_token_cucumberObject



226
227
228
# File 'lib/knapsack_pro/config/env.rb', line 226

def test_suite_token_cucumber
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER']
end

.test_suite_token_minitestObject



218
219
220
# File 'lib/knapsack_pro/config/env.rb', line 218

def test_suite_token_minitest
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST']
end

.test_suite_token_rspecObject



214
215
216
# File 'lib/knapsack_pro/config/env.rb', line 214

def test_suite_token_rspec
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC']
end

.test_suite_token_spinachObject



230
231
232
# File 'lib/knapsack_pro/config/env.rb', line 230

def test_suite_token_spinach
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH']
end

.test_suite_token_test_unitObject



222
223
224
# File 'lib/knapsack_pro/config/env.rb', line 222

def test_suite_token_test_unit
  ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT']
end

.user_seatObject



58
59
60
# File 'lib/knapsack_pro/config/env.rb', line 58

def user_seat
  env_for('KNAPSACK_PRO_USER_SEAT', :user_seat)
end