Class: PolicyCheck::ErrorList

Inherits:
Object
  • Object
show all
Defined in:
lib/policy_check/error_list.rb

Overview

A model that summarizes the errors defined in the #policy block

Instance Method Summary collapse

Constructor Details

#initialize(model, &block) ⇒ ErrorList

Returns a new instance of ErrorList.



8
9
10
11
12
13
# File 'lib/policy_check/error_list.rb', line 8

def initialize(model, &block)
  @model = model
  @block = block
  @errors = []
  instance_eval(&block)
end

Instance Method Details

#error_messagesArray<String>

Returns error messages.

Returns:

  • (Array<String>)

    error messages



21
22
23
# File 'lib/policy_check/error_list.rb', line 21

def error_messages
  errors.map(&:error_message).compact
end

#valid?Boolean

Returns true if all errors are false.

Returns:

  • (Boolean)

    true if all errors are false



16
17
18
# File 'lib/policy_check/error_list.rb', line 16

def valid?
  errors.none?(&:error?)
end