ElMassimo / ElMassimo/oj_serializers

attribute class method doesn't work without a block

Open
#13 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Ruby
Stars
166
Forks
9
Avg merge
6h 20m
Merged PRs (30d)
2

Description

I've noticed that if you have the following:

```ruby
class PostSerializer < Oj::Serializer
attribute :title
end
```

You get an error:
```ruby
undefined local variable or method `title' for #
# (eval):9:in `render_as_hash'
# /Users/david/.local/share/rtx/installs/ruby/3.0.5/lib/ruby/gems/3.0.0/gems/oj_serializers-2.0.3/lib/oj_serializers/serializer.rb:209:in `one_as_hash'
# /Users/david/.local/share/rtx/installs/ruby/3.0.5/lib/ruby/gems/3.0.0/gems/oj_serializers-2.0.3/lib/oj_serializers/serializer.rb:169:in `render_as_hash'
```
This works fine if you have a block or you use attributes:
```ruby
# works
attribute :title do
...
end

# this works too
attributes :title
```

* I have AMS compat on, if that makes any difference

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.