Module: FailFast::Utils
- Defined in:
- lib/fail_fast/base/utils.rb
Constant Summary collapse
- NO_COLOUR =
"\033[0m"- RED =
"\033[31m"- LRED =
"\033[1;31m"- BLUE =
"\033[34m"- GREEN =
"\033[32m"- YELLOW =
"\033[1;33m"
Instance Method Summary collapse
- #blank?(value) ⇒ Boolean
- #blue(str) ⇒ Object
- #green(str) ⇒ Object
- #key_value_regexp_options(key, params) ⇒ Object
- #lred(str) ⇒ Object
- #red(str) ⇒ Object
-
#value_for_deep_key(key) ⇒ Object
Usage value_for_deep_key(‘one/two/three’) returns @yaml_config_as_hash[‘two’][‘three’].
- #yellow(str) ⇒ Object
Instance Method Details
#blank?(value) ⇒ Boolean
7 8 9 |
# File 'lib/fail_fast/base/utils.rb', line 7 def blank?(value) value.nil? || (value.is_a?(String) && '' == value.strip) end |
#blue(str) ⇒ Object
52 |
# File 'lib/fail_fast/base/utils.rb', line 52 def blue( str) [BLUE, str, NO_COLOUR].join end |
#green(str) ⇒ Object
53 |
# File 'lib/fail_fast/base/utils.rb', line 53 def green( str) [GREEN, str, NO_COLOUR].join end |
#key_value_regexp_options(key, params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fail_fast/base/utils.rb', line 21 def (key, params) last = params.pop if last.is_a?(Hash) = last else params << last = {} end last = params.pop if last.is_a?(Regexp) regexp = last else params << last end key = "#{@keys_prefix}/#{key}" if @keys_prefix value = value_for_deep_key(key) Params.new(key, value, regexp, ) end |
#lred(str) ⇒ Object
51 |
# File 'lib/fail_fast/base/utils.rb', line 51 def lred( str) [LRED, str, NO_COLOUR].join end |
#red(str) ⇒ Object
50 |
# File 'lib/fail_fast/base/utils.rb', line 50 def red( str) [RED, str, NO_COLOUR].join end |
#value_for_deep_key(key) ⇒ Object
Usage
value_for_deep_key('one/two/three')
returns
@yaml_config_as_hash['one']['two']['three']
16 17 18 |
# File 'lib/fail_fast/base/utils.rb', line 16 def value_for_deep_key(key) key.to_s.split('/').inject(@yaml_config_as_hash) { |h, k| h[k] } rescue nil end |