Class: SchemaEvolutionManager::Preconditions
- Inherits:
-
Object
- Object
- SchemaEvolutionManager::Preconditions
- Defined in:
- lib/schema-evolution-manager/preconditions.rb
Overview
Class Method Summary collapse
-
.assert_class(value, klass) ⇒ Object
Asserts that value is not nill and is_?(klass).
- .assert_class_or_nil(value, klass) ⇒ Object
-
.assert_empty_opts(opts) ⇒ Object
Throws an error if opts is not empty.
- .check_argument(expression, error_message = nil) ⇒ Object
- .check_not_blank(reference, error_message = nil) ⇒ Object
- .check_not_null(reference, error_message = nil) ⇒ Object
- .check_state(expression, error_message = nil) ⇒ Object
Class Method Details
.assert_class(value, klass) ⇒ Object
Asserts that value is not nill and is_?(klass). Returns value. Common use is
amount = Preconditions.assert_class(amount, BigDecimal)
45 46 47 48 49 50 51 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 45 def Preconditions.assert_class(value, klass) Preconditions.check_not_null(value, "Value cannot be nil") Preconditions.check_not_null(klass, "Klass cannot be nil") Preconditions.check_state(value.is_a?(klass), "Value is of type[#{value.class}] - class[#{klass}] is required. value[#{value.inspect.to_s}]") value end |
.assert_class_or_nil(value, klass) ⇒ Object
53 54 55 56 57 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 53 def Preconditions.assert_class_or_nil(value, klass) if !value.nil? Preconditions.assert_class(value, klass) end end |
.assert_empty_opts(opts) ⇒ Object
Throws an error if opts is not empty. Useful when parsing arguments to a function
35 36 37 38 39 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 35 def Preconditions.assert_empty_opts(opts) if !opts.empty? raise "Invalid opts: #{opts.keys.inspect}\n#{opts.inspect}" end end |
.check_argument(expression, error_message = nil) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 5 def Preconditions.check_argument(expression, =nil) if !expression raise || "check_argument failed" end nil end |
.check_not_blank(reference, error_message = nil) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 26 def Preconditions.check_not_blank(reference, =nil) if reference.to_s.strip == "" raise || "argument cannot be blank" end reference end |
.check_not_null(reference, error_message = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 19 def Preconditions.check_not_null(reference, =nil) if reference.nil? raise || "argument cannot be nil" end reference end |
.check_state(expression, error_message = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/schema-evolution-manager/preconditions.rb', line 12 def Preconditions.check_state(expression, =nil) if !expression raise || "check_state failed" end nil end |