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.



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

#contractObject (readonly)

Returns the value of attribute contract.



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

def contract
  @contract
end

#dataObject (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

#errorsObject



14
15
16
# File 'lib/ledger_sync/util/validator.rb', line 14

def errors
  @errors ||= call_contract.errors
end

#full_messagesObject



18
19
20
# File 'lib/ledger_sync/util/validator.rb', line 18

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

#messageObject



22
23
24
# File 'lib/ledger_sync/util/validator.rb', line 22

def message
  @message ||= full_messages.first
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ledger_sync/util/validator.rb', line 26

def valid?
  call_contract.success?
end

#validateObject



30
31
32
33
34
# File 'lib/ledger_sync/util/validator.rb', line 30

def validate
  return success if valid?

  failure
end