Skip to content

Would be nice to have a :module option to decorates_association #809

@itkin

Description

@itkin

Hello,

I use drapper to decorates models in the context of my app and its admin interface.

Say for a model class Document i have 2 different decorators DocumentDecorator and Admin::DocumentDecorator.

On the other hand i heavily use STI. Currently decorates_association handle STI pretty well but not when you have more than one decorator per STI class.

Would be nice to have a :module option to decorates_association, eventually settable at the decorator class level for all associations, in order to handle STI associations more nicely :

class UserDecorator < ApplicationDecorator
  decorates_association :documents
end

class DocumentDecorator  < ApplicationDecorator
end

class BillingDocumentDecorator  < DocumentDecorator
end

class KycDocumentDecorator  < DocumentDecorator
end

class Admin::UserDecorator < UserDecorator
  decorates_association :documents, module: "Admin"
end

class Admin::DocumentDecorator  < DocumentDecorator
end

class Admin::BillingDocumentDecorator  < Admin::DocumentDecorator
end

class Admin::KycDocumentDecorator  < Admin::DocumentDecorator
end

> user = user.decorate(with: Admin::UserDecorator)
> user.documents
=> [admin_kyc_document_decorator_instance, admin_billing_document_decorator_instance, ..]

I could try to send you a pull request if you find the feature interesting let me know, thx for this nice gem.

EDIT : prefixed example instance variables with 'admin_'

Metadata

Metadata

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions