Module: Applitools::ArgumentGuard
- Extended by:
- ArgumentGuard
- Included in:
- ArgumentGuard
- Defined in:
- lib/applitools/core/argument_guard.rb
Instance Method Summary collapse
- #greater_than_or_equal_to_zero(param, param_name) ⇒ Object
- #greater_than_zero(param, param_name) ⇒ Object
- #hash(param, param_name, required_fields = []) ⇒ Object
- #is_a?(param, param_name, klass) ⇒ Boolean
- #not_nil(param, param_name) ⇒ Object
- #one_of?(param, param_name, klasses) ⇒ Boolean
- #raise_argument_error(error) ⇒ Object
Instance Method Details
#greater_than_or_equal_to_zero(param, param_name) ⇒ Object
23 24 25 |
# File 'lib/applitools/core/argument_guard.rb', line 23 def greater_than_or_equal_to_zero(param, param_name) raise Applitools::EyesIllegalArgument.new "#{param_name} < 0" if 0 > param end |
#greater_than_zero(param, param_name) ⇒ Object
27 28 29 |
# File 'lib/applitools/core/argument_guard.rb', line 27 def greater_than_zero(param, param_name) raise Applitools::EyesIllegalArgument.new "#{param_name} <= 0" if 0 >= param end |
#hash(param, param_name, required_fields = []) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/applitools/core/argument_guard.rb', line 10 def hash(param, param_name, required_fields = []) if param.is_a? Hash missed_keys = required_fields - param.keys = "Expected #{param_name} to include keys #{missed_keys.join ', '}" raise Applitools::EyesIllegalArgument.new if missed_keys.any? else = "#{param_name} expected to be a Hash" = required_fields.any? ? " containing keys #{required_fields.join(', ')}." : '.' << raise Applitools::EyesIllegalArgument.new end end |
#is_a?(param, param_name, klass) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/applitools/core/argument_guard.rb', line 31 def is_a?(param, param_name, klass) return true if param.is_a? klass raise Applitools::EyesIllegalArgument.new "Expected #{param_name} to be" \ " instance of #{klass}, but got #{param.class.name} instead" end |
#not_nil(param, param_name) ⇒ Object
6 7 8 |
# File 'lib/applitools/core/argument_guard.rb', line 6 def not_nil(param, param_name) raise Applitools::EyesIllegalArgument.new "#{param_name} is nil!" if param.nil? end |
#one_of?(param, param_name, klasses) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/applitools/core/argument_guard.rb', line 37 def one_of?(param, param_name, klasses) return true if klasses.detect { |a| param.is_a? a } raise Applitools::EyesIllegalArgument.new "Expected #{param_name} to be" \ " instance of one of this classes: [#{klasses}], but got #{param.class.name} instead" end |
#raise_argument_error(error) ⇒ Object
43 44 45 |
# File 'lib/applitools/core/argument_guard.rb', line 43 def raise_argument_error(error) raise Applitools::EyesIllegalArgument.new error end |