Module: FailFast::CheckValue
- Defined in:
- lib/fail_fast/extensions/check_value.rb
Instance Method Summary collapse
-
#has_value_for(key, *params) ⇒ Object
Usage has_value_for ‘str_key’ has_value_for :sym_key, /localhost/ returns true if succesful, false otherwise.
-
#has_values_for(*keys) ⇒ Object
Usage has_values_for :sym_key, ‘str_key’.
-
#value_of(key) ⇒ Object
Usage nda_file = value_of(:nda_file).
Instance Method Details
#has_value_for(key, *params) ⇒ Object
Usage
has_value_for 'str_key'
has_value_for :sym_key, /localhost/
returns
true if succesful, false otherwise
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fail_fast/extensions/check_value.rb', line 25 def has_value_for(key, *params) p = (key, params) key, = p.key, p. nof_errors = errors.size = [:message] if blank?(p.value) add_error ErrorDetails.new(key, :missing_value, nil, ) elsif p.regexp add_error ErrorDetails.new(key, :value_does_not_match, p.value, ) unless p.value =~ p.regexp elsif .is_a?(Hash) && [:in].is_a?(Range) add_error ErrorDetails.new(key, :value_not_in_range, p.value, ) unless [:in].include?(p.value) elsif .is_a?(Hash) && [:in].is_a?(Array) add_error ErrorDetails.new(key, :value_not_in_array, p.value, ) unless [:in].include?(p.value) end no_new_error = nof_errors == errors.size end |
#has_values_for(*keys) ⇒ Object
Usage
has_values_for :sym_key, 'str_key'
15 16 17 |
# File 'lib/fail_fast/extensions/check_value.rb', line 15 def has_values_for(*keys) keys.each{|key| has_value_for(key)} end |
#value_of(key) ⇒ Object
Usage
nda_file = value_of(:nda_file)
7 8 9 |
# File 'lib/fail_fast/extensions/check_value.rb', line 7 def value_of(key) (key, []).value end |