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 }, title_getter: -> (*) { represented.send(association).name },
show_if: -> (*) { true }, show_if: -> (*) { true },
embed_as: nil) embed_as: nil)
link property do link property.to_s.camelize(:lower) do
next unless instance_eval(&show_if) next unless instance_eval(&show_if)
value = represented.send(association) value = represented.send(association)
@ -84,15 +84,18 @@ module API
if embed_as if embed_as
embed_property property, embed_property property,
association: association, association: association,
decorator: embed_as decorator: embed_as,
show_if: show_if
end end
end end
def self.embed_property(property, association: property, decorator:) def self.embed_property(property, association: property, decorator:, show_if: true)
property association, property property,
as: property.to_s.camelize(:lower), exec_context: :decorator,
getter: -> (*) { represented.send(association) },
embedded: true, embedded: true,
decorator: decorator decorator: decorator,
if: show_if
end end
protected protected

Loading…
Cancel
Save