Class: UkrsibAPI::Models::BaseStruct

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/ukrsib_api/models/base_struct.rb

Overview

BaseStruct is a parent class for all models that require a transformer. It dynamically infers the transformer class based on the name of the child class.

Example:

class Balance < BaseStruct; end
Balance.transformer # Returns UkrsibAPI::Transformers::BalanceTransformer.new

class Transaction < BaseStruct; end
Transaction.transformer # Returns UkrsibAPI::Transformers::TransactionTransformer.new

This ensures that all subclasses of BaseStruct automatically have a transformer method without needing to redefine it in each subclass.

Direct Known Subclasses

Balance, StatementPartyDetails, StatementV3

Class Method Summary collapse

Class Method Details

.transformerObject

Returns an instance of the transformer class inferred from the child class name. Example:

class Balance < BaseStruct; end
Balance.transformer # Returns UkrsibAPI::Transformers::BalanceTransformer.new


22
23
24
25
26
27
# File 'lib/ukrsib_api/models/base_struct.rb', line 22

def self.transformer
  short_name = name.split("::").last
  transformer_class_name = "#{short_name}Transformer"
  transformer_class = UkrsibAPI::Transformers.const_get(transformer_class_name)
  transformer_class.new
end