Class: ForestAdminDatasourceMambuPayments::Plugins::Relations::HolderLinkPlugin
- Inherits:
-
ForestAdminDatasourceCustomizer::Plugins::Plugin
- Object
- ForestAdminDatasourceCustomizer::Plugins::Plugin
- ForestAdminDatasourceMambuPayments::Plugins::Relations::HolderLinkPlugin
- Defined in:
- lib/forest_admin_datasource_mambu_payments/plugins/relations/holder_link_plugin.rb
Overview
Base for AccountHolder links reached transitively through an account relation. The ‘host` imports `account_holder_id` from a related account, exposes a ManyToOne to AccountHolder, and gets a TwoStepHolderFilter (which rewrites holder filters onto `local_fk`); AccountHolder gets the reciprocal OneToMany. Subclasses configure it declaratively:
class LinkAccountHolderToIncomingPayments < HolderLinkPlugin
link host: 'MambuIncomingPayment', name: 'incoming_payments',
local_fk: 'internal_account_id', intermediate: 'MambuInternalAccount',
import_path: 'internal_account:account_holder_id'
end
Install at the datasource level: @agent.use(plugin, {}).
Direct Known Subclasses
LinkAccountHolderToDirectDebitMandates, LinkAccountHolderToIncomingPayments, LinkPaymentOrderToReceivingAccountHolder
Constant Summary collapse
- ACCOUNT_HOLDER =
'MambuAccountHolder'.freeze
- FK_NAME =
'account_holder_id'.freeze
Class Attribute Summary collapse
-
.config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.link(host:, name:, local_fk:, intermediate:, import_path:, many_to_one_name: 'account_holder') ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
-
#run(datasource_customizer, _collection_customizer = nil, _options = {}) ⇒ Object
rubocop:enable Metrics/ParameterLists.
Class Attribute Details
.config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/holder_link_plugin.rb', line 22 def config @config end |
Class Method Details
.link(host:, name:, local_fk:, intermediate:, import_path:, many_to_one_name: 'account_holder') ⇒ Object
rubocop:disable Metrics/ParameterLists
26 27 28 29 30 31 |
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/holder_link_plugin.rb', line 26 def self.link(host:, name:, local_fk:, intermediate:, import_path:, many_to_one_name: 'account_holder') @config = { host: host, name: name, local_fk: local_fk, intermediate: intermediate, import_path: import_path, many_to_one_name: many_to_one_name } end |
Instance Method Details
#run(datasource_customizer, _collection_customizer = nil, _options = {}) ⇒ Object
rubocop:enable Metrics/ParameterLists
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/holder_link_plugin.rb', line 34 def run(datasource_customizer, _collection_customizer = nil, = {}) Plugins::Helpers.require_datasource!(datasource_customizer, self.class) cfg = self.class.config datasource_customizer.customize_collection(cfg[:host]) do |c| c.import_field(FK_NAME, path: cfg[:import_path], readonly: true) c.add_many_to_one_relation(cfg[:many_to_one_name], ACCOUNT_HOLDER, foreign_key: FK_NAME, foreign_key_target: 'id') TwoStepHolderFilter.install(c, fk_name: FK_NAME, local_fk: cfg[:local_fk], intermediate_collection: cfg[:intermediate]) end datasource_customizer.customize_collection(ACCOUNT_HOLDER) do |c| c.add_one_to_many_relation(cfg[:name], cfg[:host], origin_key: FK_NAME, origin_key_target: 'id') end end |