Class: LedgerSync::Util::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/util/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contract:, data:) ⇒ Validator

Returns a new instance of Validator.



7
8
9
10
# File 'lib/ledger_sync/util/validator.rb', line 7

def initialize(contract:, data:)
  @data = data
  @contract = contract
end

Instance Attribute Details

#contractObject (readonly)

Returns the value of attribute contract.



4
5
6
# File 'lib/ledger_sync/util/validator.rb', line 4

def contract
  @contract
end

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/ledger_sync/util/validator.rb', line 4

def data
  @data
end

Instance Method Details

#errorsObject



12
13
14
# File 'lib/ledger_sync/util/validator.rb', line 12

def errors
  @errors ||= call_contract.errors
end

#full_messagesObject



16
17
18
# File 'lib/ledger_sync/util/validator.rb', line 16

def full_messages
  @full_messages ||= errors.messages.map { |e| "#{e.path.map(&:to_s).join(' ')} #{e.text}"}
end

#messageObject



20
21
22
# File 'lib/ledger_sync/util/validator.rb', line 20

def message
  @message ||= full_messages.first
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ledger_sync/util/validator.rb', line 24

def valid?
  call_contract.success?
end

#validateObject



28
29
30
31
32
# File 'lib/ledger_sync/util/validator.rb', line 28

def validate
  return success if valid?

  failure
end