Project defined attribute types should be valid#13
Project defined attribute types should be valid#13CristianCurteanu wants to merge 2 commits intoyammer:masterfrom
Conversation
Added project defined types validation
|
|
|
Hi, thanks for the contribution. Can you explain a little more what you're trying to achieve with your change? I'm a little concerned that what you're trying to do might be in opposition to what the gem's initial aims are - to support creating a model that fronts an HTTP web service. Particularly (from the readme):
I think you're trying to allow attributes that have arbitrary Ruby types. But how are these then serialized to JSON? JSON doesn't allow arbitrary types. If you wanted to have an address attribute with Address type, for example, then I'd suggest setting the attribute to be JSON type, and provide your own accessors on the model that handle converting an Address instance to a JSON friendly hash. If you build the Address model using ModelAttribute then |
|
Hello! Actually instead of |
|
Whatever the class of the object you want to use, it will still not have a simple conversion to JSON primitives. This is where your change goes against the intent of this gem. |
It can be handy to add valid type to attributes that are defined within a project scope. In this pull request I have tried to make such functionality possible, and to make possible to add value types for classes that are defined. If the type/class is not defined, then
UnsupportedTypeErrorexception still should be thrownAlso, there was made some refactoring to
ModelAttribute::Castsmodule class methods, to be a bit more decoupled from.castmethod