mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge branch 'ouvrages-exclude_nil_links'
This commit is contained in:
commit
cd9689683c
@ -5,6 +5,7 @@
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
- [#1668](https://github.com/rails-api/active_model_serializers/pull/1668) Exclude nil and empty links. (@sigmike)
|
||||||
- [#1426](https://github.com/rails-api/active_model_serializers/pull/1426) Add ActiveModelSerializers.config.default_includes (@empact)
|
- [#1426](https://github.com/rails-api/active_model_serializers/pull/1426) Add ActiveModelSerializers.config.default_includes (@empact)
|
||||||
|
|
||||||
Fixes:
|
Fixes:
|
||||||
|
|||||||
@ -474,7 +474,8 @@ module ActiveModelSerializers
|
|||||||
# }.reject! {|_,v| v.nil? }
|
# }.reject! {|_,v| v.nil? }
|
||||||
def links_for(serializer)
|
def links_for(serializer)
|
||||||
serializer._links.each_with_object({}) do |(name, value), hash|
|
serializer._links.each_with_object({}) do |(name, value), hash|
|
||||||
hash[name] = Link.new(serializer, value).as_json
|
result = Link.new(serializer, value).as_json
|
||||||
|
hash[name] = result if result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ module ActiveModelSerializers
|
|||||||
hash[:href] = @href if defined?(@href)
|
hash[:href] = @href if defined?(@href)
|
||||||
hash[:meta] = @meta if defined?(@meta)
|
hash[:meta] = @meta if defined?(@meta)
|
||||||
|
|
||||||
hash
|
hash.any? ? hash : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@ -17,6 +17,7 @@ module ActiveModelSerializers
|
|||||||
link :yet_another do
|
link :yet_another do
|
||||||
"http://example.com/resource/#{object.id}"
|
"http://example.com/resource/#{object.id}"
|
||||||
end
|
end
|
||||||
|
link(:nil) { nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user