Merge pull request #2740 from NobodysNightmare/feature/helper_fixes

[API] Fixes for linked_property helper
pull/2744/head
ulferts 10 years ago
commit 748062f994
  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