lib/ledger_sync/adaptors/adaptor.rb in ledger_sync-1.3.3 vs lib/ledger_sync/adaptors/adaptor.rb in ledger_sync-1.3.4

- old
+ new

@@ -29,10 +29,20 @@ Hash[self.class.ledger_attributes_to_save.map do |attribute| [attribute, send(attribute)] end] end + def operation_for(method:, resource:) + self.class.operation_class_for( + method: method, + resource_class: resource.class + ).new( + adaptor: self, + resource: resource + ) + end + def searcher_for?(resource_type:) searcher_klass_for(resource_type: resource_type) rescue NameError false end @@ -64,9 +74,27 @@ # 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. def self.ledger_attributes_to_save raise NotImplementedError + end + + def self.ledger_resource_type_for(resource_class:) + ledger_resource_type_overrides[resource_class] || resource_class.resource_type.to_s + end + + def self.ledger_resource_type_overrides + {} + end + + def self.operation_class_for(method:, resource_class:) + base_operation_module_for(resource_class: resource_class) + .const_get(LedgerSync::Util::StringHelpers.camelcase(method.to_s)) + end + + def self.resource_from_ledger_type(type:, converter: nil) + converter ||= Proc.new { |n| n.underscore } + ledger_resource_type_overrides.invert[converter.call(type).to_sym] || LedgerSync.resources[converter.call(type).to_sym] end def self.url_for(resource: nil); end end end