Module: DailyAffirmation::Affirmations

Defined in:
lib/daily_affirmation/affirmations.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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_messagesArray<String>

Returns an array of error message if any, otherwise an empty array.

Returns:

  • (Array<String>)


37
38
39
# File 'lib/daily_affirmation/affirmations.rb', line 37

def error_messages
  validate[1]
end

#initialize(object) ⇒ self

Creates a new instance of the validator.

Parameters:

  • object (Object)

    the object to validate.

Returns:

  • (self)


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.

Returns:

  • (true, false)


18
19
20
# File 'lib/daily_affirmation/affirmations.rb', line 18

def valid?
  validate[0]
end

#validateArray(Boolean, Array<String>)

Returns an array of length 2 telling you if the object is valid, along with any error messages.

Returns:

  • (Array(Boolean, Array<String>))

    Array of length 2 containing validation results.



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