Module: DailyAffirmation::Affirmations
- Defined in:
- lib/daily_affirmation/affirmations.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#error_messages ⇒ Array<String>
Returns an array of error message if any, otherwise an empty array.
-
#initialize(object) ⇒ self
Creates a new instance of the validator.
-
#valid? ⇒ true, false
Tells you if the object is valid based on the affirmations.
-
#validate ⇒ Array(Boolean, Array<String>)
Returns an array of length 2 telling you if the object is valid, along with any error messages.
Class Method Details
.included(descendant) ⇒ Object
3 4 5 |
# File 'lib/daily_affirmation/affirmations.rb', line 3 def self.included(descendant) descendant.extend(ClassMethods) end |
Instance Method Details
#error_messages ⇒ Array<String>
Returns an array of error message if any, otherwise an empty array.
37 38 39 |
# File 'lib/daily_affirmation/affirmations.rb', line 37 def validate[1] end |
#initialize(object) ⇒ self
Creates a new instance of the validator.
11 12 13 |
# File 'lib/daily_affirmation/affirmations.rb', line 11 def initialize(object) self.object = object end |
#valid? ⇒ true, false
Tells you if the object is valid based on the affirmations.
18 19 20 |
# File 'lib/daily_affirmation/affirmations.rb', line 18 def valid? validate[0] end |
#validate ⇒ Array(Boolean, Array<String>)
Returns an array of length 2 telling you if the object is valid, along with any error messages.
27 28 29 30 31 32 |
# File 'lib/daily_affirmation/affirmations.rb', line 27 def validate @validate ||= [ affirmations.map(&:first).all?, affirmations.map(&:last).compact ] end |