New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline Decorators #52
Comments
Can you give us the decorator class that is broken? |
I haven't looked deeply into this yet, but my intuition says lib/representable/decorator.rb |
I meant your decorator that breaks. It should work, check this test: https://github.com/apotonick/representable/blob/master/test/representable_test.rb#L465 |
Whoops, sorry! This class does not work: class ArticlesRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
collection :all,
as: :article,
class: Article,
embedded: true do
property :latitude
property :longitude
link :self do
{ href: article_path(represented), title: represented.title }
end
end
end The error it give is: {
"error": "NoMethodError",
"message": "undefined method `to_hash' for #<Article:0x007f97f5066758>"
} This one does: class ArticlesRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
itemDecorator = Class.new(Roar::Decorator) do
include Roar::Representer::JSON::HAL
property :latitude
property :longitude
link :self do
{ href: article_path(represented), title: represented.title }
end
end
collection :all,
as: :article,
class: Article,
decorator: itemDecorator,
embedded: true
end Full app at xaethos/roar-hal-demo |
Ah, you were right, because |
This may be fixed by #54. |
Confirmed that the inline decorator described above now works. |
We still need a test for that. |
Similar problem is with works: class RegionsRepresenter < Representable::Decorator
include Representable::JSON::Collection
item_decorator = Class.new(Representable::Decorator) do
include Representable::JSON
property :id
property :name
end
items decorator: item_decorator
end Raises Argument Error (0 for 1) for class RegionsRepresenter < Representable::Decorator
include Representable::JSON::Collection
items do
property :id
property :name
end
end I'm not sure if this is separate issue or it belongs here? |
|
Haha, I am stupid, it is early and I didn't read it properly. I don't think using an inline representer in combination with |
👌 |
@jandudulski Fixed in 86ac6a6 |
They appear to be broken. I can create an anonymous class and assign it to the
:decorator
key, but when trying to use a block I get a NoMethodError on represented#to_hash. After some light skimming through the code, I suspect this may be a problem with#representer_engine
not being defined on Representable::Decorator.The text was updated successfully, but these errors were encountered: