You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rather than requiring users to write/generate boilerplate code for each resource, it shouldn't be too hard to allow users to define resources with a DSL and provide hooks for customization, e.g.
# app/resources/api/v1/post.rbPragma::Resource.define:postdo |config| # entire block is optionalconfig.model_class= ::Post# optional, computed by defaultconfig.attributesdo |attributes|
attributes.define:title,:bodydotype:stringvalidate:required?endattributes.define:authordodefault->(options){options['current_user']}validate:required?visiblefalse# not exposed in decoratorendattributes.define:send_newsletterdotype:booleanonly:create# cannot be updatedvirtual# not saved to modelendend# These would accept any callable object which receives `options`.# We would also have before_* and around_* hooks.config.hooksdo |hooks|
hooks.after_createAPI::V1::Post::Hook::NotifySubscribershooks.after_updateAPI::V1::Post::Hook::TouchLastUpdatehooks.after_saveAPI::V1::Post::Hook::GenerateSummaryhooks.after_destroyAPI::V1::Post::Hook::RemoveFromFeedendconfig.policydo |policy|
policy.on:create?do |user,post|
# ...endendend
We should still support custom resources defined the old way.
This would probably be a separate library/gem (Pragma::Resource?) providing a catch-all API endpoint that looks at the configuration and executes the appropriate logic.
The text was updated successfully, but these errors were encountered:
Rather than requiring users to write/generate boilerplate code for each resource, it shouldn't be too hard to allow users to define resources with a DSL and provide hooks for customization, e.g.
We should still support custom resources defined the old way.
This would probably be a separate library/gem (
Pragma::Resource
?) providing a catch-all API endpoint that looks at the configuration and executes the appropriate logic.The text was updated successfully, but these errors were encountered: