Skip to content
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

Default options #43

Open
Nerian opened this issue Feb 20, 2013 · 6 comments
Open

Default options #43

Nerian opened this issue Feb 20, 2013 · 6 comments

Comments

@Nerian
Copy link

Nerian commented Feb 20, 2013

It would be awesome if we could have a clean way to specify default options for all properties in a single line.

Example:

module BandRepresenter
  include Roar::Representer::JSON
  include Roar::Representer::Feature::Hypermedia

  # This is how I do it right now
  def self.property(name, options={})
    super(name, options.merge!(render_nil: true))
  end

  # This is how I would like to do it.
  default_options render_nil: true

  property :id
  property :whatever1
  property :whatever2
  property :whatever3
  property :whatever4
  property :whatever5
end

Thanks

@jsmpereira
Copy link

+1

@skwp
Copy link

skwp commented Jan 23, 2015

+1, would love this feature. We are having a fun issue:

  1. using property to create a json hash
  2. reading back the json hash from a search engine (elasticsearch)
  3. using a DelegateClass to wrap that hash..it throws errors because some methods are not defined because they got represented as nil and therefore didn't make it into the representation at all

@skwp
Copy link

skwp commented Jan 23, 2015

Here's the solution we used to monkeypatch Roar to define this globally
https://gist.github.com/skwp/5afe7b2a238260f301ac

@apotonick
Copy link
Member

Ok, I can see how this is helpful. The defaults will be copied to inline representers, right?

@waiting-for-dev
Copy link

It would be even greater (I would say it is a must) to be able to configure defaults in a global way (for all representers). I'm thinking in render_nil option, which usually is an overall API decision, so it would be also tiring to have to declare it in each representer.

@richkettle
Copy link

@waiting-for-dev Hi, did the global defaults feature get implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants