GithubHelp home page GithubHelp logo

Comments (4)

myabc avatar myabc commented on July 20, 2024

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.

myabc avatar myabc commented on July 20, 2024

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.

myabc avatar myabc commented on July 20, 2024

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.

myabc avatar myabc commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.