Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Node without a block should call source method named #236

Closed
mtodd opened this Issue · 7 comments

2 participants

@mtodd

node should just use the name as a method name on the source object if no block is given.

For example:

class Source
  def foo
    "bar"
  end
end
node :foo

Would generate something similar to:

{"source":{"foo":"bar"}}

Here's one minimal possibility to make it work:

def node(name = nil, options={}, &block)
  block = @_source.method(name) unless block_given?
  @_options[:node].push({ :name => name, :options => options, :block => block })
end

Also supporting either nodes or allowing node to handle multiple values like this would be awesome.

@nesquena
Owner

You can achieve this with attributes:

def foo
  "bar"
end

and then:

attributes :foo, :bar

Attributes is for attaching things directly associated from the object. Node is specifically intended for nodes that do not map directly to an object method.

@nesquena
Owner

Also supporting either nodes or allowing node to handle multiple values like this would be awesome.

On this second point, could you give me an example use case (usage and expected output)?

@mtodd

OK, so attributes is supposed to be any method, not just attributes. Wasn't clear on that fact, and when I tried to use method names in my list, they were totally skipped in my output.

I'll dig deeper and figure out what's happening.

:metal:

@mtodd mtodd closed this
@nesquena
Owner

Yeah exactly attributes amounts to any method that can be called on an object since rabl is orm-agnostic. Method names should work so if they are being skipped for some reason in your case then I would be interested to understand what's happening and address any bugs related to that. Let me know if/when you have more details.

@mtodd

Turns out it was just failing silently when attributes listed don't exist.

I was referring to a method that was mistakenly on another object but it wasn't blowing up, it was just failing silently.

@mtodd

Yeah, the change above to node isn't needed.

:sparkles: Disregard. :sparkles:

Thanks for the quick response.

@nesquena
Owner

Yeah I will admit the failing silently can sometimes be a bit confusing. I chose to have it do this for cases where we might have a heterogenous collection in which not all items in a list share all attributes.

Anyhow, thanks for following up and let me know if you run into any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.