Class: LedgerSync::Adaptors::Adaptor

Inherits:
Object
  • Object
show all
Includes:
Fingerprintable::Mixin, Validatable, SimplySerializable::Mixin
Defined in:
lib/ledger_sync/adaptors/adaptor.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#valid?, #validate, #validate_or_fail

Constructor Details

#initializeAdaptor

Returns a new instance of Adaptor.

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 14

def initialize(*)
  raise NotImplementedError
end

Class Method Details

.base_moduleObject



52
53
54
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 52

def self.base_module
  config.base_module
end

.base_operation_module_for(resource_class:) ⇒ Object



56
57
58
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 56

def self.base_operation_module_for(resource_class:)
  base_module.const_get("#{resource_class.resource_module_str}::Operations")
end

.configObject



60
61
62
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 60

def self.config
  @config ||= LedgerSync.adaptors.config_from_klass(klass: self)
end

.ledger_attributes_to_saveObject

These are attributes that must always be saved after the adaptor is called. For example, the library will handle refreshing tokens that will need to be saved back to the application layer for future use.

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 67

def self.ledger_attributes_to_save
  raise NotImplementedError
end

.url_for(resource: nil) ⇒ Object



71
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 71

def self.url_for(resource: nil); end

Instance Method Details

#adaptor_configurationObject



18
19
20
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 18

def adaptor_configuration
  self.class.config
end

#base_moduleObject



22
23
24
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 22

def base_module
  self.class.base_module
end

#ledger_attributes_to_saveObject



26
27
28
29
30
31
32
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 26

def ledger_attributes_to_save
  return {} if self.class.ledger_attributes_to_save.nil?

  Hash[self.class.ledger_attributes_to_save.map do |attribute|
    [attribute, send(attribute)]
  end]
end

#parse_operation_errorObject



48
49
50
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 48

def parse_operation_error(*)
  nil
end

#searcher_for?(resource_type:) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 34

def searcher_for?(resource_type:)
  searcher_klass_for(resource_type: resource_type)
rescue NameError
  false
end

#searcher_klass_for(resource_type:) ⇒ Object



40
41
42
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 40

def searcher_klass_for(resource_type:)
  base_module.const_get(LedgerSync::Util::StringHelpers.camelcase(resource_type.to_s))::Searcher
end

#url_for(*_args) ⇒ Object

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/ledger_sync/adaptors/adaptor.rb', line 44

def url_for(*_args)
  raise NotImplementedError
end