Class: KnapsackPro::Config::Env
- Inherits:
-
Object
- Object
- KnapsackPro::Config::Env
- 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
- .branch ⇒ Object
- .branch_encrypted ⇒ Object
- .branch_encrypted? ⇒ Boolean
- .ci? ⇒ Boolean
- .ci_node_build_id ⇒ Object
- .ci_node_index ⇒ Object
- .ci_node_retry_count ⇒ Object
- .ci_node_total ⇒ Object
- .ci_provider ⇒ Object
- .commit_hash ⇒ Object
- .cucumber_queue_prefix ⇒ Object
- .detected_ci ⇒ Object
- .endpoint ⇒ Object
- .fallback_mode_enabled ⇒ Object
- .fallback_mode_enabled? ⇒ Boolean
- .fallback_mode_error_exit_code ⇒ Object
- .fixed_queue_split ⇒ Object
- .fixed_queue_split? ⇒ Boolean
- .fixed_test_suite_split ⇒ Object
- .fixed_test_suite_split? ⇒ Boolean
- .log_dir ⇒ Object
- .log_level ⇒ Object
- .masked_user_seat ⇒ Object
- .max_request_retries ⇒ Object
- .mode ⇒ Object
- .project_dir ⇒ Object
- .queue_id ⇒ Object
- .queue_recording_enabled ⇒ Object
- .queue_recording_enabled? ⇒ Boolean
- .recording_enabled ⇒ Object
- .recording_enabled? ⇒ Boolean
- .regular_mode? ⇒ Boolean
- .repository_adapter ⇒ Object
- .rspec_split_by_test_examples? ⇒ Boolean
- .rspec_test_example_detector_prefix ⇒ Object
- .salt ⇒ Object
- .set_test_runner_adapter(adapter_class) ⇒ Object
- .slow_test_file_pattern ⇒ Object
- .slow_test_file_threshold ⇒ Object
- .slow_test_file_threshold? ⇒ Boolean
- .subset_queue_id ⇒ Object
- .test_dir ⇒ Object
- .test_file_exclude_pattern ⇒ Object
- .test_file_list ⇒ Object
- .test_file_list_source_file ⇒ Object
- .test_file_pattern ⇒ Object
- .test_files_encrypted ⇒ Object
- .test_files_encrypted? ⇒ Boolean
- .test_runner_adapter ⇒ Object
- .test_suite_token ⇒ Object
- .test_suite_token_cucumber ⇒ Object
- .test_suite_token_minitest ⇒ Object
- .test_suite_token_rspec ⇒ Object
- .test_suite_token_spinach ⇒ Object
- .test_suite_token_test_unit ⇒ Object
- .user_seat ⇒ Object
Class Method Details
.branch ⇒ Object
44 45 46 |
# File 'lib/knapsack_pro/config/env.rb', line 44 def branch env_for('KNAPSACK_PRO_BRANCH', :branch) end |
.branch_encrypted ⇒ Object
134 135 136 |
# File 'lib/knapsack_pro/config/env.rb', line 134 def branch_encrypted ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED'] end |
.branch_encrypted? ⇒ Boolean
138 139 140 |
# File 'lib/knapsack_pro/config/env.rb', line 138 def branch_encrypted? branch_encrypted == 'true' end |
.ci? ⇒ Boolean
282 283 284 285 |
# File 'lib/knapsack_pro/config/env.rb', line 282 def ci? ENV.fetch('CI', 'false').downcase == 'true' || detected_ci != KnapsackPro::Config::CI::Base end |
.ci_node_build_id ⇒ Object
23 24 25 26 27 |
# File 'lib/knapsack_pro/config/env.rb', line 23 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_index ⇒ Object
19 20 21 |
# File 'lib/knapsack_pro/config/env.rb', line 19 def ci_node_index (env_for('KNAPSACK_PRO_CI_NODE_INDEX', :node_index) || 0).to_i end |
.ci_node_retry_count ⇒ Object
29 30 31 |
# File 'lib/knapsack_pro/config/env.rb', line 29 def ci_node_retry_count (env_for('KNAPSACK_PRO_CI_NODE_RETRY_COUNT', :node_retry_count) || 0).to_i end |
.ci_node_total ⇒ Object
15 16 17 |
# File 'lib/knapsack_pro/config/env.rb', line 15 def ci_node_total (env_for('KNAPSACK_PRO_CI_NODE_TOTAL', :node_total) || 1).to_i end |
.ci_provider ⇒ Object
262 263 264 |
# File 'lib/knapsack_pro/config/env.rb', line 262 def ci_provider detected_ci.new.ci_provider end |
.commit_hash ⇒ Object
40 41 42 |
# File 'lib/knapsack_pro/config/env.rb', line 40 def commit_hash env_for('KNAPSACK_PRO_COMMIT_HASH', :commit_hash) end |
.cucumber_queue_prefix ⇒ Object
187 188 189 |
# File 'lib/knapsack_pro/config/env.rb', line 187 def cucumber_queue_prefix ENV.fetch('KNAPSACK_PRO_CUCUMBER_QUEUE_PREFIX', 'bundle exec') end |
.detected_ci ⇒ Object
252 253 254 255 256 257 258 259 260 |
# File 'lib/knapsack_pro/config/env.rb', line 252 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 |
.endpoint ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/knapsack_pro/config/env.rb', line 146 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_enabled ⇒ Object
118 119 120 |
# File 'lib/knapsack_pro/config/env.rb', line 118 def fallback_mode_enabled ENV.fetch('KNAPSACK_PRO_FALLBACK_MODE_ENABLED', true) end |
.fallback_mode_enabled? ⇒ Boolean
122 123 124 |
# File 'lib/knapsack_pro/config/env.rb', line 122 def fallback_mode_enabled? fallback_mode_enabled.to_s == 'true' end |
.fallback_mode_error_exit_code ⇒ Object
287 288 289 |
# File 'lib/knapsack_pro/config/env.rb', line 287 def fallback_mode_error_exit_code ENV.fetch('KNAPSACK_PRO_FALLBACK_MODE_ERROR_EXIT_CODE', 1).to_i end |
.fixed_queue_split ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/knapsack_pro/config/env.rb', line 170 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
183 184 185 |
# File 'lib/knapsack_pro/config/env.rb', line 183 def fixed_queue_split? fixed_queue_split.to_s == 'true' end |
.fixed_test_suite_split ⇒ Object
162 163 164 |
# File 'lib/knapsack_pro/config/env.rb', line 162 def fixed_test_suite_split ENV.fetch('KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT', true) end |
.fixed_test_suite_split? ⇒ Boolean
166 167 168 |
# File 'lib/knapsack_pro/config/env.rb', line 166 def fixed_test_suite_split? fixed_test_suite_split.to_s == 'true' end |
.log_dir ⇒ Object
270 271 272 |
# File 'lib/knapsack_pro/config/env.rb', line 270 def log_dir ENV['KNAPSACK_PRO_LOG_DIR'] end |
.log_level ⇒ Object
266 267 268 |
# File 'lib/knapsack_pro/config/env.rb', line 266 def log_level LOG_LEVELS[ENV['KNAPSACK_PRO_LOG_LEVEL'].to_s.downcase] || ::Logger::INFO end |
.masked_user_seat ⇒ Object
56 57 58 59 60 |
# File 'lib/knapsack_pro/config/env.rb', line 56 def masked_user_seat return unless user_seat KnapsackPro::MaskString.call(user_seat) end |
.max_request_retries ⇒ Object
33 34 35 36 37 38 |
# File 'lib/knapsack_pro/config/env.rb', line 33 def max_request_retries number = ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] if number number.to_i end end |
.mode ⇒ Object
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/knapsack_pro/config/env.rb', line 241 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_dir ⇒ Object
48 49 50 |
# File 'lib/knapsack_pro/config/env.rb', line 48 def project_dir env_for('KNAPSACK_PRO_PROJECT_DIR', :project_dir) end |
.queue_id ⇒ Object
110 111 112 |
# File 'lib/knapsack_pro/config/env.rb', line 110 def queue_id ENV['KNAPSACK_PRO_QUEUE_ID'] || raise('Missing Queue ID') end |
.queue_recording_enabled ⇒ Object
102 103 104 |
# File 'lib/knapsack_pro/config/env.rb', line 102 def queue_recording_enabled ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] end |
.queue_recording_enabled? ⇒ Boolean
106 107 108 |
# File 'lib/knapsack_pro/config/env.rb', line 106 def queue_recording_enabled? queue_recording_enabled == 'true' end |
.recording_enabled ⇒ Object
90 91 92 |
# File 'lib/knapsack_pro/config/env.rb', line 90 def recording_enabled ENV['KNAPSACK_PRO_RECORDING_ENABLED'] end |
.recording_enabled? ⇒ Boolean
94 95 96 |
# File 'lib/knapsack_pro/config/env.rb', line 94 def recording_enabled? recording_enabled == 'true' end |
.regular_mode? ⇒ Boolean
98 99 100 |
# File 'lib/knapsack_pro/config/env.rb', line 98 def regular_mode? recording_enabled? end |
.repository_adapter ⇒ Object
86 87 88 |
# File 'lib/knapsack_pro/config/env.rb', line 86 def repository_adapter ENV['KNAPSACK_PRO_REPOSITORY_ADAPTER'] end |
.rspec_split_by_test_examples? ⇒ Boolean
191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/knapsack_pro/config/env.rb', line 191 def rspec_split_by_test_examples? return @rspec_split_by_test_examples if defined?(@rspec_split_by_test_examples) split = ENV.fetch('KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES', false).to_s == 'true' if split && ci_node_total < 2 KnapsackPro.logger.debug('Skipping split of test files by test examples because you are running tests on a single CI node (no parallelism)') @rspec_split_by_test_examples = false else @rspec_split_by_test_examples = split end end |
.rspec_test_example_detector_prefix ⇒ Object
204 205 206 |
# File 'lib/knapsack_pro/config/env.rb', line 204 def rspec_test_example_detector_prefix ENV.fetch('KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX', 'bundle exec') end |
.salt ⇒ Object
142 143 144 |
# File 'lib/knapsack_pro/config/env.rb', line 142 def salt required_env('KNAPSACK_PRO_SALT') end |
.set_test_runner_adapter(adapter_class) ⇒ Object
278 279 280 |
# File 'lib/knapsack_pro/config/env.rb', line 278 def set_test_runner_adapter(adapter_class) ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] = adapter_class.to_s.split('::').last end |
.slow_test_file_pattern ⇒ Object
66 67 68 |
# File 'lib/knapsack_pro/config/env.rb', line 66 def slow_test_file_pattern ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] end |
.slow_test_file_threshold ⇒ Object
208 209 210 |
# File 'lib/knapsack_pro/config/env.rb', line 208 def slow_test_file_threshold ENV.fetch('KNAPSACK_PRO_SLOW_TEST_FILE_THRESHOLD', nil)&.to_f end |
.slow_test_file_threshold? ⇒ Boolean
212 213 214 |
# File 'lib/knapsack_pro/config/env.rb', line 212 def slow_test_file_threshold? !!slow_test_file_threshold end |
.subset_queue_id ⇒ Object
114 115 116 |
# File 'lib/knapsack_pro/config/env.rb', line 114 def subset_queue_id ENV['KNAPSACK_PRO_SUBSET_QUEUE_ID'] || raise('Missing Subset Queue ID') end |
.test_dir ⇒ Object
82 83 84 |
# File 'lib/knapsack_pro/config/env.rb', line 82 def test_dir ENV['KNAPSACK_PRO_TEST_DIR'] end |
.test_file_exclude_pattern ⇒ Object
70 71 72 |
# File 'lib/knapsack_pro/config/env.rb', line 70 def test_file_exclude_pattern ENV['KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN'] end |
.test_file_list ⇒ Object
74 75 76 |
# File 'lib/knapsack_pro/config/env.rb', line 74 def test_file_list ENV['KNAPSACK_PRO_TEST_FILE_LIST'] end |
.test_file_list_source_file ⇒ Object
78 79 80 |
# File 'lib/knapsack_pro/config/env.rb', line 78 def test_file_list_source_file ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE'] end |
.test_file_pattern ⇒ Object
62 63 64 |
# File 'lib/knapsack_pro/config/env.rb', line 62 def test_file_pattern ENV['KNAPSACK_PRO_TEST_FILE_PATTERN'] end |
.test_files_encrypted ⇒ Object
126 127 128 |
# File 'lib/knapsack_pro/config/env.rb', line 126 def test_files_encrypted ENV['KNAPSACK_PRO_TEST_FILES_ENCRYPTED'] end |
.test_files_encrypted? ⇒ Boolean
130 131 132 |
# File 'lib/knapsack_pro/config/env.rb', line 130 def test_files_encrypted? test_files_encrypted == 'true' end |
.test_runner_adapter ⇒ Object
274 275 276 |
# File 'lib/knapsack_pro/config/env.rb', line 274 def test_runner_adapter ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] end |
.test_suite_token ⇒ Object
216 217 218 219 |
# File 'lib/knapsack_pro/config/env.rb', line 216 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_cucumber ⇒ Object
233 234 235 |
# File 'lib/knapsack_pro/config/env.rb', line 233 def test_suite_token_cucumber ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER'] end |
.test_suite_token_minitest ⇒ Object
225 226 227 |
# File 'lib/knapsack_pro/config/env.rb', line 225 def test_suite_token_minitest ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST'] end |
.test_suite_token_rspec ⇒ Object
221 222 223 |
# File 'lib/knapsack_pro/config/env.rb', line 221 def test_suite_token_rspec ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC'] end |
.test_suite_token_spinach ⇒ Object
237 238 239 |
# File 'lib/knapsack_pro/config/env.rb', line 237 def test_suite_token_spinach ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH'] end |
.test_suite_token_test_unit ⇒ Object
229 230 231 |
# File 'lib/knapsack_pro/config/env.rb', line 229 def test_suite_token_test_unit ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT'] end |
.user_seat ⇒ Object
52 53 54 |
# File 'lib/knapsack_pro/config/env.rb', line 52 def user_seat env_for('KNAPSACK_PRO_USER_SEAT', :user_seat) end |