Class: LedgerSync::Adaptors::Adaptor

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

Direct Known Subclasses

QuickBooksOnline::Adaptor, Test::Adaptor

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

.configObject



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

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)


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

def self.ledger_attributes_to_save
  raise NotImplementedError
end

.url_for(resource: nil) ⇒ Object



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

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
  adaptor_configuration.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