Comments (4)
From @apotonick on November 30, 2015 21:2
Yes, here you go: http://trailblazer.to/gems/representable/3.0/api.html#defaults
from roar-jsonapi.
From @thhermansen on December 1, 2015 8:56
Thank you for pointing me to defaults. I had forgotten that I had tried it a week or two ago. It didn't seem be inherited in nested properties and has_one. Maybe it isn't supposed to. To give a complete example of what I have, without calling defaults:
require 'roar/decorator'
require 'roar/json/json_api'
module PlaytimeTube
module Representers
class Playback < Roar::Decorator
include Roar::JSON::JSONAPI
type :playbacks
property :id
property :starts_at, as: 'starts-at', render_nil: true
property :duration_in_seconds, as: 'duration-in-seconds'
property :type
property :recording do
property :local_id, as: 'local-id'
# more properties
property :artist_name, as: 'artist-name'
end
has_one :playtime_report, as: 'playtime-report' do
type 'playtime-reports'
property :id
# more properties
property :archive_url, as: 'archive-url'
end
end
end
end
If i provide defaults
with a block which dasherize the name right above type :playbacks
it works for the Playback's properties, like starts_at
, but it doesn't inherit to local_id
within recording
, nor in to playtime_report
's properties like archive_url
.
I can call defaults
within property
/has_one
and it will work. Is there a better way, or should I simply use defaults within each given block?
from roar-jsonapi.
From @apotonick on December 3, 2015 8:19
Defaults are not "inherited" into nested representers. I need to think about if that's a good idea or if we should introduce a inline: true
option or something.
Will let you know tomorrow!
from roar-jsonapi.
From @thhermansen on December 3, 2015 9:17
Oki, thank you. I solved it for now by doing:
DASHERIZE_NAME = -> (name, options) { {as: dasherize-the-string(name) } }
defaults &DASHERIZE_NAME
And reuse that block of code in the nested representers.
from roar-jsonapi.
Related Issues (20)
- [JSON-API] Nested polymorphic representation HOT 5
- JSON-API support for :extends/:decorator with has_one
- [JSON-API] Relationship links HOT 11
- References represented inside of link block using JSONAPI implementation HOT 4
- JSON-API representer does not work with Roar::Client HOT 1
- Properties convert as camelize(:lower) HOT 6
- Representers: `defaults` block is lost in nested declarations HOT 3
- Collection representation HOT 8
- Update Operation with Roar JSONAPI representer forces contract to open up id HOT 1
- double included fields HOT 4
- Compound Documents not rendered per JSONAPI standard? HOT 2
- Performance issue when decorator files are loaded multiple times HOT 4
- Collections `to_json(included: 'xxx')` doesn't output included records HOT 9
- Representer attributes with null values are excluded from resource document
- Should be able to return relationship links without including the related representer
- How to set the type of included items? HOT 5
- Using JSONAPI HOT 4
- [JSON-API] Rendering an empty relationship HOT 3
- [JSON-API] Recursive has_many :children (include tree) HOT 2
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 roar-jsonapi.