nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.64k stars 334 forks source link

Ruby 2.3.0 breaks the condition resolver of the builder #649

Closed vmeyet closed 8 years ago

vmeyet commented 8 years ago

The fix in #608 is incompatible with ruby 2.3.0.

working as follow

>> [:a, :b, :c].map(&{a: 2, c: 3}.to_proc)
=> [2, nil, 3]
def call_condition_proc(condition, object)
  # This will evaluate lambda, proc & symbol and call it with 1 argument
  return condition.to_proc.call(object) if condition.respond_to?(:to_proc)
  # Else we send directly the object
  condition
end

Relying on the duck typing of the existence of :to_proc this is now not valid anymore.

since a condition such as

@data = { some: 'info' }
node(:myNode, if: @data) { @data }

#> This used to return a node with the hash `{ some: 'info' }`
#> in 2.3.0 this returns nothing

Fix can be simply to replace duck typing by type checking:

  ...
  return condition.to_proc.call(object) if condition.is_a?(Proc) || condition.is_a?(Symbol)
  ...
nesquena commented 8 years ago

Thanks, closed by #650, appreciate the help. Will release new version soon

shaicoleman commented 8 years ago

Could you please release a new version?

cthorner commented 8 years ago

+1 for new release

seanculver commented 8 years ago

+1

nesquena commented 8 years ago

0.12.0 has been released. Sorry for the delay.

seanculver commented 8 years ago

:+1: Thank you!!!!