Class: SoftValidation::SoftValidationMethod
- Inherits:
-
Object
- Object
- SoftValidation::SoftValidationMethod
- Defined in:
- lib/soft_validation/soft_validation_method.rb
Overview
A metadata structure for each soft validation
Instance Attribute Summary collapse
-
#description ⇒ String?
human description of this soft validation.
-
#fix ⇒ Symbol?
The name of the method that will fix this issue.
-
#flagged ⇒ Boolean
Flagged methods are not executed by default.
-
#klass ⇒ Object
the (base) klass that has method.
-
#method ⇒ Object
the soft validation method.
-
#name ⇒ String?
Human name/title of this soft validation.
- #resolution ⇒ Array
-
#set ⇒ Symbol?
Assign this soft validation method to a set.
Instance Method Summary collapse
-
#described? ⇒ Boolean
@return a name and description provided.
- #fixable? ⇒ Boolean
- #flagged? ⇒ Boolean
-
#initialize(options) ⇒ SoftValidationMethod
constructor
A new instance of SoftValidationMethod.
-
#matches?(is_fixable, include_flagged = false) ⇒ Boolean
private
Boolean true - the soft validation method should be retained false - the soft validation method does not match, it will be excluded from soft_validate().
-
#resolutions? ⇒ Boolean
@return whether there resolutions.
-
#to_s ⇒ Object
@return a human readable string describing the general point of this soft validation method.
Constructor Details
#initialize(options) ⇒ SoftValidationMethod
Returns a new instance of SoftValidationMethod.
39 40 41 42 43 44 |
# File 'lib/soft_validation/soft_validation_method.rb', line 39 def initialize() raise(SoftValidationError, 'missing method and klass') if [:method].nil? || [:klass].nil? .each do |k,v| send("#{k}=", v) end end |
Instance Attribute Details
#description ⇒ String?
human description of this soft validation
20 21 22 |
# File 'lib/soft_validation/soft_validation_method.rb', line 20 def description @description end |
#fix ⇒ Symbol?
Returns the name of the method that will fix this issue.
32 33 34 |
# File 'lib/soft_validation/soft_validation_method.rb', line 32 def fix @fix end |
#flagged ⇒ Boolean
Returns flagged methods are not executed by default.
36 37 38 |
# File 'lib/soft_validation/soft_validation_method.rb', line 36 def flagged @flagged end |
#klass ⇒ Object
the (base) klass that has method
12 13 14 |
# File 'lib/soft_validation/soft_validation_method.rb', line 12 def klass @klass end |
#method ⇒ Object
the soft validation method
8 9 10 |
# File 'lib/soft_validation/soft_validation_method.rb', line 8 def method @method end |
#name ⇒ String?
Returns human name/title of this soft validation.
16 17 18 |
# File 'lib/soft_validation/soft_validation_method.rb', line 16 def name @name end |
#resolution ⇒ Array
24 25 26 |
# File 'lib/soft_validation/soft_validation_method.rb', line 24 def resolution @resolution end |
#set ⇒ Symbol?
Returns assign this soft validation method to a set.
28 29 30 |
# File 'lib/soft_validation/soft_validation_method.rb', line 28 def set @set end |
Instance Method Details
#described? ⇒ Boolean
a name and description provided
62 63 64 |
# File 'lib/soft_validation/soft_validation_method.rb', line 62 def described? !name.blank? && !description.blank? end |
#fixable? ⇒ Boolean
73 74 75 |
# File 'lib/soft_validation/soft_validation_method.rb', line 73 def fixable? @fix.kind_of?(Symbol) end |
#flagged? ⇒ Boolean
78 79 80 |
# File 'lib/soft_validation/soft_validation_method.rb', line 78 def flagged? @flagged == true end |
#matches?(is_fixable, include_flagged = false) ⇒ Boolean (private)
Returns Boolean true - the soft validation method should be retained false - the soft validation method does not match, it will be excluded from soft_validate().
99 100 101 102 103 |
# File 'lib/soft_validation/soft_validation_method.rb', line 99 def matches?(is_fixable, include_flagged = false) a = is_fixable.nil? ? true : (is_fixable ? fixable? : true) b = include_flagged == true ? true : !flagged a && b end |
#resolutions? ⇒ Boolean
whether there resolutions
68 69 70 |
# File 'lib/soft_validation/soft_validation_method.rb', line 68 def resolutions? resolution.size > 0 end |
#to_s ⇒ Object
a human readable string describing the general point of this soft validation method
84 85 86 |
# File 'lib/soft_validation/soft_validation_method.rb', line 84 def to_s [(name.blank? ? "#{method} (temporary name)" : name), (description.blank? ? '(no description provided)' : description)].join(': ') end |