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_env_for(env_name) ⇒ Object
- .ci_node_build_id ⇒ Object
- .ci_node_index ⇒ Object
- .ci_node_retry_count ⇒ Object
- .ci_node_total ⇒ Object
- .commit_hash ⇒ Object
- .cucumber_queue_prefix ⇒ Object
- .endpoint ⇒ Object
- .fallback_mode_enabled ⇒ Object
- .fallback_mode_enabled? ⇒ Boolean
- .fixed_queue_split ⇒ Object
- .fixed_queue_split? ⇒ Boolean
- .fixed_test_suite_split ⇒ Object
- .fixed_test_suite_split? ⇒ Boolean
- .log_dir ⇒ Object
- .log_level ⇒ Object
- .max_request_retries ⇒ Object
- .mode ⇒ Object
- .modify_default_rspec_formatters ⇒ Object
- .modify_default_rspec_formatters? ⇒ Boolean
- .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 ⇒ 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
- .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
- .user_seat_hash ⇒ Object
Class Method Details
.branch ⇒ Object
52 53 54 55 |
# File 'lib/knapsack_pro/config/env.rb', line 52 def branch ENV['KNAPSACK_PRO_BRANCH'] || ci_env_for(:branch) end |
.branch_encrypted ⇒ Object
152 153 154 |
# File 'lib/knapsack_pro/config/env.rb', line 152 def branch_encrypted ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED'] end |
.branch_encrypted? ⇒ Boolean
156 157 158 |
# File 'lib/knapsack_pro/config/env.rb', line 156 def branch_encrypted? branch_encrypted == 'true' end |
.ci_env_for(env_name) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/knapsack_pro/config/env.rb', line 248 def ci_env_for(env_name) value = nil ci_list = KnapsackPro::Config::CI.constants - [:Base, :GitlabCI] # load GitLab CI first to avoid edge case with order of loading envs for CI_NODE_INDEX ci_list = [:GitlabCI] + ci_list ci_list.each do |ci_name| ci_class = Object.const_get("KnapsackPro::Config::CI::#{ci_name}") ci = ci_class.new value = ci.send(env_name) break unless value.nil? end value end |
.ci_node_build_id ⇒ Object
25 26 27 28 29 30 |
# File 'lib/knapsack_pro/config/env.rb', line 25 def ci_node_build_id env_name = 'KNAPSACK_PRO_CI_NODE_BUILD_ID' ENV[env_name] || ci_env_for(: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 22 23 |
# File 'lib/knapsack_pro/config/env.rb', line 19 def ci_node_index (ENV['KNAPSACK_PRO_CI_NODE_INDEX'] || ci_env_for(:node_index) || 0).to_i end |
.ci_node_retry_count ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/knapsack_pro/config/env.rb', line 32 def ci_node_retry_count ( ENV['KNAPSACK_PRO_CI_NODE_RETRY_COUNT'] || ci_env_for(:node_retry_count) || 0 ).to_i end |
.ci_node_total ⇒ Object
13 14 15 16 17 |
# File 'lib/knapsack_pro/config/env.rb', line 13 def ci_node_total (ENV['KNAPSACK_PRO_CI_NODE_TOTAL'] || ci_env_for(:node_total) || 1).to_i end |
.commit_hash ⇒ Object
47 48 49 50 |
# File 'lib/knapsack_pro/config/env.rb', line 47 def commit_hash ENV['KNAPSACK_PRO_COMMIT_HASH'] || ci_env_for(:commit_hash) end |
.cucumber_queue_prefix ⇒ Object
196 197 198 |
# File 'lib/knapsack_pro/config/env.rb', line 196 def cucumber_queue_prefix ENV.fetch('KNAPSACK_PRO_CUCUMBER_QUEUE_PREFIX', 'bundle exec') end |
.endpoint ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/knapsack_pro/config/env.rb', line 164 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
128 129 130 |
# File 'lib/knapsack_pro/config/env.rb', line 128 def fallback_mode_enabled ENV.fetch('KNAPSACK_PRO_FALLBACK_MODE_ENABLED', true) end |
.fallback_mode_enabled? ⇒ Boolean
132 133 134 |
# File 'lib/knapsack_pro/config/env.rb', line 132 def fallback_mode_enabled? fallback_mode_enabled.to_s == 'true' end |
.fixed_queue_split ⇒ Object
188 189 190 |
# File 'lib/knapsack_pro/config/env.rb', line 188 def fixed_queue_split ENV.fetch('KNAPSACK_PRO_FIXED_QUEUE_SPLIT', false) end |
.fixed_queue_split? ⇒ Boolean
192 193 194 |
# File 'lib/knapsack_pro/config/env.rb', line 192 def fixed_queue_split? fixed_queue_split.to_s == 'true' end |
.fixed_test_suite_split ⇒ Object
180 181 182 |
# File 'lib/knapsack_pro/config/env.rb', line 180 def fixed_test_suite_split ENV.fetch('KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT', true) end |
.fixed_test_suite_split? ⇒ Boolean
184 185 186 |
# File 'lib/knapsack_pro/config/env.rb', line 184 def fixed_test_suite_split? fixed_test_suite_split.to_s == 'true' end |
.log_dir ⇒ Object
266 267 268 |
# File 'lib/knapsack_pro/config/env.rb', line 266 def log_dir ENV['KNAPSACK_PRO_LOG_DIR'] end |
.log_level ⇒ Object
262 263 264 |
# File 'lib/knapsack_pro/config/env.rb', line 262 def log_level LOG_LEVELS[ENV['KNAPSACK_PRO_LOG_LEVEL'].to_s.downcase] || ::Logger::DEBUG end |
.max_request_retries ⇒ Object
40 41 42 43 44 45 |
# File 'lib/knapsack_pro/config/env.rb', line 40 def max_request_retries number = ENV['KNAPSACK_PRO_MAX_REQUEST_RETRIES'] if number number.to_i end end |
.mode ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/knapsack_pro/config/env.rb', line 237 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 |
.modify_default_rspec_formatters ⇒ Object
144 145 146 |
# File 'lib/knapsack_pro/config/env.rb', line 144 def modify_default_rspec_formatters ENV.fetch('KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS', true) end |
.modify_default_rspec_formatters? ⇒ Boolean
148 149 150 |
# File 'lib/knapsack_pro/config/env.rb', line 148 def modify_default_rspec_formatters? modify_default_rspec_formatters.to_s == 'true' end |
.project_dir ⇒ Object
57 58 59 60 |
# File 'lib/knapsack_pro/config/env.rb', line 57 def project_dir ENV['KNAPSACK_PRO_PROJECT_DIR'] || ci_env_for(:project_dir) end |
.queue_id ⇒ Object
120 121 122 |
# File 'lib/knapsack_pro/config/env.rb', line 120 def queue_id ENV['KNAPSACK_PRO_QUEUE_ID'] || raise('Missing Queue ID') end |
.queue_recording_enabled ⇒ Object
112 113 114 |
# File 'lib/knapsack_pro/config/env.rb', line 112 def queue_recording_enabled ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] end |
.queue_recording_enabled? ⇒ Boolean
116 117 118 |
# File 'lib/knapsack_pro/config/env.rb', line 116 def queue_recording_enabled? queue_recording_enabled == 'true' end |
.recording_enabled ⇒ Object
100 101 102 |
# File 'lib/knapsack_pro/config/env.rb', line 100 def recording_enabled ENV['KNAPSACK_PRO_RECORDING_ENABLED'] end |
.recording_enabled? ⇒ Boolean
104 105 106 |
# File 'lib/knapsack_pro/config/env.rb', line 104 def recording_enabled? recording_enabled == 'true' end |
.regular_mode? ⇒ Boolean
108 109 110 |
# File 'lib/knapsack_pro/config/env.rb', line 108 def regular_mode? recording_enabled? end |
.repository_adapter ⇒ Object
96 97 98 |
# File 'lib/knapsack_pro/config/env.rb', line 96 def repository_adapter ENV['KNAPSACK_PRO_REPOSITORY_ADAPTER'] end |
.rspec_split_by_test_examples ⇒ Object
200 201 202 |
# File 'lib/knapsack_pro/config/env.rb', line 200 def rspec_split_by_test_examples ENV.fetch('KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES', false) end |
.rspec_split_by_test_examples? ⇒ Boolean
204 205 206 |
# File 'lib/knapsack_pro/config/env.rb', line 204 def rspec_split_by_test_examples? rspec_split_by_test_examples.to_s == 'true' end |
.rspec_test_example_detector_prefix ⇒ Object
208 209 210 |
# File 'lib/knapsack_pro/config/env.rb', line 208 def rspec_test_example_detector_prefix ENV.fetch('KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIX', 'bundle exec') end |
.salt ⇒ Object
160 161 162 |
# File 'lib/knapsack_pro/config/env.rb', line 160 def salt required_env('KNAPSACK_PRO_SALT') end |
.set_test_runner_adapter(adapter_class) ⇒ Object
274 275 276 |
# File 'lib/knapsack_pro/config/env.rb', line 274 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
76 77 78 |
# File 'lib/knapsack_pro/config/env.rb', line 76 def slow_test_file_pattern ENV['KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN'] end |
.subset_queue_id ⇒ Object
124 125 126 |
# File 'lib/knapsack_pro/config/env.rb', line 124 def subset_queue_id ENV['KNAPSACK_PRO_SUBSET_QUEUE_ID'] || raise('Missing Subset Queue ID') end |
.test_dir ⇒ Object
92 93 94 |
# File 'lib/knapsack_pro/config/env.rb', line 92 def test_dir ENV['KNAPSACK_PRO_TEST_DIR'] end |
.test_file_exclude_pattern ⇒ Object
80 81 82 |
# File 'lib/knapsack_pro/config/env.rb', line 80 def test_file_exclude_pattern ENV['KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN'] end |
.test_file_list ⇒ Object
84 85 86 |
# File 'lib/knapsack_pro/config/env.rb', line 84 def test_file_list ENV['KNAPSACK_PRO_TEST_FILE_LIST'] end |
.test_file_list_source_file ⇒ Object
88 89 90 |
# File 'lib/knapsack_pro/config/env.rb', line 88 def test_file_list_source_file ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE'] end |
.test_file_pattern ⇒ Object
72 73 74 |
# File 'lib/knapsack_pro/config/env.rb', line 72 def test_file_pattern ENV['KNAPSACK_PRO_TEST_FILE_PATTERN'] end |
.test_files_encrypted ⇒ Object
136 137 138 |
# File 'lib/knapsack_pro/config/env.rb', line 136 def test_files_encrypted ENV['KNAPSACK_PRO_TEST_FILES_ENCRYPTED'] end |
.test_files_encrypted? ⇒ Boolean
140 141 142 |
# File 'lib/knapsack_pro/config/env.rb', line 140 def test_files_encrypted? test_files_encrypted == 'true' end |
.test_runner_adapter ⇒ Object
270 271 272 |
# File 'lib/knapsack_pro/config/env.rb', line 270 def test_runner_adapter ENV['KNAPSACK_PRO_TEST_RUNNER_ADAPTER'] end |
.test_suite_token ⇒ Object
212 213 214 215 |
# File 'lib/knapsack_pro/config/env.rb', line 212 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
229 230 231 |
# File 'lib/knapsack_pro/config/env.rb', line 229 def test_suite_token_cucumber ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER'] end |
.test_suite_token_minitest ⇒ Object
221 222 223 |
# File 'lib/knapsack_pro/config/env.rb', line 221 def test_suite_token_minitest ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST'] end |
.test_suite_token_rspec ⇒ Object
217 218 219 |
# File 'lib/knapsack_pro/config/env.rb', line 217 def test_suite_token_rspec ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC'] end |
.test_suite_token_spinach ⇒ Object
233 234 235 |
# File 'lib/knapsack_pro/config/env.rb', line 233 def test_suite_token_spinach ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH'] end |
.test_suite_token_test_unit ⇒ Object
225 226 227 |
# File 'lib/knapsack_pro/config/env.rb', line 225 def test_suite_token_test_unit ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT'] end |
.user_seat ⇒ Object
62 63 64 65 |
# File 'lib/knapsack_pro/config/env.rb', line 62 def user_seat ENV['KNAPSACK_PRO_USER_SEAT'] || ci_env_for(:user_seat) end |
.user_seat_hash ⇒ Object
67 68 69 70 |
# File 'lib/knapsack_pro/config/env.rb', line 67 def user_seat_hash return unless user_seat Digest::SHA2.hexdigest(user_seat) end |