fast_jsonapi icon indicating copy to clipboard operation
fast_jsonapi copied to clipboard

Flipped ArgumentError with conditional attributes

Open coconup opened this issue 7 years ago • 2 comments

Conditional attributes are throwing me an ArgumentError if I don't give two arguments to the Proc passed to the if: keyword:

  attribute :my_attribute, if: ->(obj) { obj.my_condition }

returns ArgumentError: wrong number of arguments (given 2, expected 1) (shouldn't it be the other way around, if anything?)

Passing a second argument, on the other hand, makes things work just fine:

  attribute :my_attribute, if: ->(obj, _) { obj.my_condition }

coconup avatar Aug 17 '18 12:08 coconup

@coconup if params are not passed in we should probably set it to a default empty hash. Is this something you can make a pull request for ?

shishirmk avatar Aug 23 '18 03:08 shishirmk

@shishirmk here you go: https://github.com/Netflix/fast_jsonapi/pull/305

coconup avatar Aug 23 '18 05:08 coconup