spira 0.0.12 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +0,0 @@
1
- module Spira
2
- module Resource
3
-
4
- ##
5
- # Instance methods relating to validations for a Spira resource. This
6
- # includes the default assertions.
7
- #
8
- # @see Spira::Resource::InstanceMethods
9
- # @see Spira::Resource::ClassMethods
10
- # @see Spira::Resource::DSL
11
- module Validations
12
-
13
- ##
14
- # Assert a fact about this instance. If the given expression is false,
15
- # an error will be noted.
16
- #
17
- # @example Assert that a title is correct
18
- # assert(title == 'xyz', :title, 'bad title')
19
- # @param [Any] boolean The expression to evaluate
20
- # @param [Symbol] property The property or has_many to mark as incorrect on failure
21
- # @param [String] message The message to record if this assertion fails
22
- # @return [Void]
23
- def assert(boolean, property, message)
24
- errors.add(property, message) unless boolean
25
- end
26
-
27
- ##
28
- # A default helper assertion. Asserts that a given property is set.
29
- #
30
- # @param [Symbol] name The property to check
31
- # @return [Void]
32
- def assert_set(name)
33
- assert(!(self.send(name).nil?), name, "#{name.to_s} cannot be nil")
34
- end
35
-
36
- ##
37
- # A default helper assertion. Asserts that a given property is numeric.
38
- #
39
- # @param [Symbol] name The property to check
40
- # @return [Void]
41
- def assert_numeric(name)
42
- assert(self.send(name).is_a?(Numeric), name, "#{name.to_s} must be numeric (was #{self.send(name)})")
43
- end
44
-
45
- end
46
- end
47
- end