two fixes for the linked_property helper

- also hide embedded objects when show_if is false
- camelize links correctly
pull/2740/head
Jan Sandbrink 10 years ago
parent c649bb47d8
commit c24ff68ab8
  1. 15
      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

Loading…
Cancel
Save