Class: LedgerSync::Util::Validator
- Inherits:
-
Object
- Object
- LedgerSync::Util::Validator
- Defined in:
- lib/ledger_sync/util/validator.rb
Instance Attribute Summary collapse
-
#contract ⇒ Object
readonly
Returns the value of attribute contract.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #errors ⇒ Object
- #full_messages ⇒ Object
-
#initialize(contract:, data:) ⇒ Validator
constructor
A new instance of Validator.
- #message ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(contract:, data:) ⇒ Validator
Returns a new instance of Validator.
9 10 11 12 |
# File 'lib/ledger_sync/util/validator.rb', line 9 def initialize(contract:, data:) @data = data @contract = contract end |
Instance Attribute Details
#contract ⇒ Object (readonly)
Returns the value of attribute contract.
6 7 8 |
# File 'lib/ledger_sync/util/validator.rb', line 6 def contract @contract end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/ledger_sync/util/validator.rb', line 6 def data @data end |
Instance Method Details
#errors ⇒ Object
14 15 16 |
# File 'lib/ledger_sync/util/validator.rb', line 14 def errors @errors ||= call_contract.errors end |
#full_messages ⇒ Object
18 19 20 |
# File 'lib/ledger_sync/util/validator.rb', line 18 def ||= errors..map { |e| "#{e.path.map(&:to_s).join(' ')} #{e.text}" } end |
#message ⇒ Object
22 23 24 |
# File 'lib/ledger_sync/util/validator.rb', line 22 def ||= .first end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/ledger_sync/util/validator.rb', line 26 def valid? call_contract.success? end |
#validate ⇒ Object
30 31 32 33 34 |
# File 'lib/ledger_sync/util/validator.rb', line 30 def validate return success if valid? failure end |