From c24ff68ab809dc0bdf9942b3c6099d15dcc90d23 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Tue, 24 Mar 2015 11:07:12 +0100 Subject: [PATCH] two fixes for the linked_property helper - also hide embedded objects when show_if is false - camelize links correctly --- lib/api/decorators/single.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/api/decorators/single.rb b/lib/api/decorators/single.rb index b9a162ca6d..3431078470 100644 --- a/lib/api/decorators/single.rb +++ b/lib/api/decorators/single.rb @@ -67,7 +67,7 @@ module API title_getter: -> (*) { represented.send(association).name }, show_if: -> (*) { true }, embed_as: nil) - link property do + link property.to_s.camelize(:lower) do next unless instance_eval(&show_if) value = represented.send(association) @@ -84,15 +84,18 @@ module API if embed_as embed_property property, association: association, - decorator: embed_as + decorator: embed_as, + show_if: show_if end end - def self.embed_property(property, association: property, decorator:) - property association, - as: property.to_s.camelize(:lower), + def self.embed_property(property, association: property, decorator:, show_if: true) + property property, + exec_context: :decorator, + getter: -> (*) { represented.send(association) }, embedded: true, - decorator: decorator + decorator: decorator, + if: show_if end protected