Comments (1)
I wonder whether this could be implemented in the form of response transformers, e.g.
class Pragma::Transformer::CastSymbol < Pragma::Transformer::Base
def call(options)
return unless options['result.response'].is_a?(Symbol)
response_klass = "Pragma::Operation::Response::#{options['result.response'].to_s.camelize}"
options['result.response'] = response_klass.constantize
end
end
class Pragma::Transformer::Instantiate < Pragma::Transformer::Base
def call(options)
return unless options['result.response'] < Pragma::Operation::Response::Base
options['result.response'] = options['result.response'].new
end
end
class Pragma::Transformer::DecorateErrors < Pragma::Transformer::Base
def call(options)
return unless options['result.response'].entity.is_a?(Pragma::Error)
options['result.response'].decorate_with(Pragma::Decorator::Error)
end
end
Pragma::Operation::Base.transformers << Pragma::Transformer::CastSymbol
Pragma::Operation::Base.transformers << Pragma::Transformer::Instantiate
Pragma::Operation::Base.transformers << Pragma::Transformer::DecorateErrors
Then we could do
options['result.response'] = :not_found
and get the response instantiated and decorated.
I imagine this would be its own gem. In any case, it only makes sense if it would also be used in other places.
My other concern is that this could very easily be abused to add steps to an operation without having to call step
. Perhaps we should only allow to manipulate the response and nothing else?
from pragma.
Related Issues (20)
- Model(): Support lookup by custom attributes HOT 1
- Normalize pipetrees
- Support namespaces in Classes
- Support IdentityCache HOT 1
- Move fail_fast to default macro configuration
- Policy(): Support overriding action name
- Classes() does not support nested operations
- Simplify responding
- Contract::Sync(): Implement macro
- Expose `type' for errors
- Indicate where an operation has halted HOT 1
- Extract ORM-specific logic in pragma-orm
- Pragma::Metadata
- Pragma::Auth HOT 1
- Resource definition DSL
- Improve error message when classes cannot be found
- Extract AR calls in default operations to Pragma::ORM HOT 1
- Schema() macro for headless validation
- Any update on some tutorials for best testing and documentation practices? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pragma.