Module: LedgerSync::Ledgers::TestLedger::Operation::Mixin::InstanceMethods

Defined in:
lib/ledger_sync/test/support/test_ledger/operation.rb

Instance Method Summary collapse

Instance Method Details

#deserialized_resource(response:) ⇒ Object



14
15
16
17
18
19
# File 'lib/ledger_sync/test/support/test_ledger/operation.rb', line 14

def deserialized_resource(response:)
  deserializer.deserialize(
    hash: response.body[test_ledger_resource_type.to_s.camelize],
    resource: resource
  )
end

#ledger_resource_pathObject



21
22
23
# File 'lib/ledger_sync/test/support/test_ledger/operation.rb', line 21

def ledger_resource_path
  @ledger_resource_path ||= "#{ledger_resource_type_for_path}/#{resource.ledger_id}"
end

#ledger_resource_type_for_pathObject



25
26
27
# File 'lib/ledger_sync/test/support/test_ledger/operation.rb', line 25

def ledger_resource_type_for_path
  test_ledger_resource_type.tr('_', '')
end

#response_to_operation_result(response:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ledger_sync/test/support/test_ledger/operation.rb', line 29

def response_to_operation_result(response:)
  if response.success?
    success(
      resource: deserialized_resource(response: response),
      response: response
    )
  else
    failure(
      Error::OperationError.new(
        operation: self,
        response: response
      )
    )
  end
end

#test_ledger_resource_typeObject



45
46
47
# File 'lib/ledger_sync/test/support/test_ledger/operation.rb', line 45

def test_ledger_resource_type
  @test_ledger_resource_type ||= client.class.ledger_resource_type_for(resource_class: resource.class)
end