Class: TestBench::Settings::Environment
- Inherits:
-
Object
- Object
- TestBench::Settings::Environment
- Defined in:
- lib/test_bench/settings/environment.rb
Instance Attribute Summary collapse
- #env ⇒ Object
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Class Method Summary collapse
Instance Method Summary collapse
- #abort_on_error ⇒ Object
- #activated?(value) ⇒ Boolean
- #affirmative_pattern ⇒ Object
- #call ⇒ Object
- #color ⇒ Object
- #deactivated?(value) ⇒ Boolean
- #exclude_pattern ⇒ Object
-
#initialize(settings) ⇒ Environment
constructor
A new instance of Environment.
- #invalid_boolean(value) ⇒ Object
- #negative_pattern ⇒ Object
- #quiet ⇒ Object
- #record_telemetry ⇒ Object
- #reverse_backtraces ⇒ Object
- #tests_dir ⇒ Object
- #verbose ⇒ Object
Constructor Details
#initialize(settings) ⇒ Environment
Returns a new instance of Environment.
7 8 9 |
# File 'lib/test_bench/settings/environment.rb', line 7 def initialize settings @settings = settings end |
Instance Attribute Details
#env ⇒ Object
67 68 69 |
# File 'lib/test_bench/settings/environment.rb', line 67 def env @env ||= {} end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
4 5 6 |
# File 'lib/test_bench/settings/environment.rb', line 4 def settings @settings end |
Class Method Details
.build(settings, env = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/test_bench/settings/environment.rb', line 11 def self.build settings, env=nil env ||= ENV instance = new settings instance.env = env instance end |
.call(*arguments) ⇒ Object
19 20 21 22 |
# File 'lib/test_bench/settings/environment.rb', line 19 def self.call *arguments instance = build(*arguments) instance.() end |
Instance Method Details
#abort_on_error ⇒ Object
71 72 73 74 75 |
# File 'lib/test_bench/settings/environment.rb', line 71 def abort_on_error if activated? env['TEST_BENCH_ABORT_ON_ERROR'] settings.abort_on_error = true end end |
#activated?(value) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/test_bench/settings/environment.rb', line 35 def activated? value if affirmative_pattern.match value true elsif value.nil? or negative_pattern.match value false else invalid_boolean value end end |
#affirmative_pattern ⇒ Object
45 46 47 |
# File 'lib/test_bench/settings/environment.rb', line 45 def affirmative_pattern @@affirmative_pattern ||= %r{\A(?:on|yes|y|1)\z}i end |
#call ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/test_bench/settings/environment.rb', line 24 def call abort_on_error color exclude_pattern reverse_backtraces quiet record_telemetry tests_dir verbose end |
#color ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/test_bench/settings/environment.rb', line 49 def color if deactivated? env['TEST_BENCH_COLOR'] settings.color = false elsif activated? env['TEST_BENCH_COLOR'] settings.color = true end end |
#deactivated?(value) ⇒ Boolean
57 58 59 60 61 62 63 64 65 |
# File 'lib/test_bench/settings/environment.rb', line 57 def deactivated? value if negative_pattern.match value true elsif value.nil? or affirmative_pattern.match value false else invalid_boolean value end end |
#exclude_pattern ⇒ Object
77 78 79 80 81 |
# File 'lib/test_bench/settings/environment.rb', line 77 def exclude_pattern if pattern = env['TEST_BENCH_EXCLUDE_PATTERN'] settings.exclude_pattern = pattern end end |
#invalid_boolean(value) ⇒ Object
83 84 85 |
# File 'lib/test_bench/settings/environment.rb', line 83 def invalid_boolean value raise ArgumentError, %{Invalid boolean value #{value.inspect}; values that are toggled can be set via "on" or "off", "yes" or "no", "y" or "n", or "0" or "1".} end |
#negative_pattern ⇒ Object
87 88 89 |
# File 'lib/test_bench/settings/environment.rb', line 87 def negative_pattern @@negative_pattern ||= %r{\A(?:off|no|n|0)\z}i end |
#quiet ⇒ Object
103 104 105 106 107 108 |
# File 'lib/test_bench/settings/environment.rb', line 103 def quiet if activated? env['TEST_BENCH_QUIET'] settings.lower_verbosity settings.lower_verbosity end end |
#record_telemetry ⇒ Object
91 92 93 94 95 |
# File 'lib/test_bench/settings/environment.rb', line 91 def record_telemetry if activated? env['TEST_BENCH_RECORD_TELEMETRY'] settings.record_telemetry = true end end |
#reverse_backtraces ⇒ Object
97 98 99 100 101 |
# File 'lib/test_bench/settings/environment.rb', line 97 def reverse_backtraces if activated? env['TEST_BENCH_REVERSE_BACKTRACES'] settings.reverse_backtraces = true end end |
#tests_dir ⇒ Object
110 111 112 113 114 |
# File 'lib/test_bench/settings/environment.rb', line 110 def tests_dir tests_dir = env['TEST_BENCH_TESTS_DIR'] settings.tests_dir = tests_dir if tests_dir end |
#verbose ⇒ Object
116 117 118 119 120 121 |
# File 'lib/test_bench/settings/environment.rb', line 116 def verbose if activated? env['TEST_BENCH_VERBOSE'] settings.raise_verbosity settings.raise_verbosity end end |