plexus / yaks

Ruby library for building hypermedia APIs
http://rubygems.org/gems/yaks
MIT License
236 stars 26 forks source link

Setting `type` to a symbol raises an exception #120

Open Odaeus opened 8 years ago

Odaeus commented 8 years ago

The JSON API example in the README shows the following:

class AnimalMapper < Yaks::Mapper
  type :pet
end

But using a symbol results in an exception:

broken_type.rb

# ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
/home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/inflection-1.0.0/lib/inflection.rb:212:in `dup': can't dup Symbol (TypeError)
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/inflection-1.0.0/lib/inflection.rb:212:in `plural'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/format/json_api.rb:39:in `serialize_resource'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/format/json_api.rb:16:in `call'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/pipeline.rb:6:in `block in call'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/pipeline.rb:6:in `each'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/pipeline.rb:6:in `inject'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/pipeline.rb:6:in `call'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/runner.rb:13:in `call'
        from /home/andrew/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/yaks-0.12.0/lib/yaks/config.rb:87:in `call'
        from broken_type.rb:17:in `<main>'

Using a string for the type value works. Not sure if docs or code are wrong. I imagine supporting symbols is preferable. 😀