trestle
trestle copied to clipboard
Ability to generate base resource
It would be great if we could have the ability to generate a base resource somehow.
Even something like:
Trestle.resource(:post) do
include BaseResource
end
module BaseResource
def self.included(r)
r.scope :active, -> { model.kept }, default: true
r.scope :deleted, -> { model.unscoped.discarded }
r.delete_instance do |instance|
instance.discard
end
end
end
It will give us the following error:
undefined method `include' for #<Trestle::Resource::Builder:0x00007f9c1ce3c848>
Related to https://github.com/TrestleAdmin/trestle/issues/161
Have you found a solution to your problem ? I have the same problem.
I definitely want to implement some nicer support for pluggable/extendable functionality like this. For now though, the best way to do this would be something like this:
BaseResource = -> {
scope :active, -> { model.kept }, default: true
scope :deleted, -> { model.unscoped.discarded }
delete_instance do |instance|
instance.discard
end
}
Trestle.resource(:post) do
instance_exec(&BaseResource)
end