-
Notifications
You must be signed in to change notification settings - Fork 13
Added support for versionned JSON #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I like the structure above for declaring json_fields for different versions; I wonder whether others would prefer a single json_fields \
:name => { :versions => [ :v1 ], :definition => lambda { |instance| "#{instance.first} #{instance.last}" } },
:first => { :versions => [ :v2 ] },
:last => { :versions => [ :v2 ] } I suspect a majority would prefer what you already have, but might be worth a quick poll. |
@@ -78,6 +80,30 @@ Mongoid::CachedJson.configure do |config| | |||
end | |||
``` | |||
|
|||
Versionning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Versioning"
You're right, it's possible people will want a declaration where you say whether a field applies to this or that version. That would be pretty nightmarish to manage imo, because when you add :v3, you have to go back to all JSONs and add it into each declaration? Unless of course versions is a range, but that has some of its own disadvantages. @aaw - thoughts? |
This looks great, and is a very useful feature. I would probably add a |
This looks good, though, I'd say it's merge-able whenever you want. |
I like Frank's idea - I think in most cases, the intersection between the field definitions in two different versions of an API will be large, and it's going to get unmanageable once you have several json_fields_for declarations in the same class. We should support ranges of versions, but it doesn't need to be much more syntax than you have already - the common case is that you've added a new field in a new version, the not-so-common case is that you've removed a field in a new version, so maybe something like:
Which would mean that :name is in version 1 and above, :middle is in every version, :first is in version 2 and above, and :last was in version 2 and version 3 but not version 4 or above. |
I am going to close this, reopened https://github.com/dblock/mongoid-cached-json/pull/3 with the inline version. I took most of the suggestions except the retiring part - I think it's pretty dangerous to assume that the version is something sortable and incrementable - I might want the :red version or the :blue version. |
Mongoid::CachedJson now supports JSON versionning with json_fields_for. The obvious use-case is to return different JSON versions from API v1 and API v2. For example, version 2 of Widget splits name into first and last.
JSON fields declared with json_fields instead of json_fields_for are used for all versions.