From 4fc8aa1cf34373a8a39b7a579d107108961d0e75 Mon Sep 17 00:00:00 2001 From: Bhushan Lodha Date: Mon, 1 Mar 2021 11:51:40 +0530 Subject: [PATCH 1/4] server tags metadata as ._metadata --- lib/contentful/management/resource/metadata.rb | 14 +++++--------- spec/lib/contentful/management/asset_spec.rb | 4 ++-- spec/lib/contentful/management/entry_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/contentful/management/resource/metadata.rb b/lib/contentful/management/resource/metadata.rb index 1433a53..e0d7baa 100644 --- a/lib/contentful/management/resource/metadata.rb +++ b/lib/contentful/management/resource/metadata.rb @@ -4,25 +4,21 @@ module Resource # Adds metadata logic for [Resource] classes module Metadata # Returns the metadata hash - # - # @return [Hash] Metadata - def metadata - @metadata - end + attr_reader :_metadata # @private def initialize(object = nil, *) super - @metadata = {} + @_metadata = {} extract_metadata_from_object! object if object end # @private def inspect(info = nil) - if metadata.empty? + if _metadata.empty? super(info) else - super("#{info} @metadata=#{metadata.inspect}") + super("#{info} @_metadata=#{_metadata.inspect}") end end @@ -31,7 +27,7 @@ def inspect(info = nil) def extract_metadata_from_object!(object) return unless object.key?('metadata') object['metadata'].each do |key, value| - @metadata[key.to_sym] = if key == 'tags' + @_metadata[key.to_sym] = if key == 'tags' coerce_tags(value) else value diff --git a/spec/lib/contentful/management/asset_spec.rb b/spec/lib/contentful/management/asset_spec.rb index 2237afe..ae193b9 100644 --- a/spec/lib/contentful/management/asset_spec.rb +++ b/spec/lib/contentful/management/asset_spec.rb @@ -474,14 +474,14 @@ module Management it 'hydrates tags' do vcr('asset/issue_219') { asset = environment.assets.find(asset_id) - expect(asset.metadata[:tags].first).to be_a Contentful::Management::Link + expect(asset._metadata[:tags].first).to be_a Contentful::Management::Link } end it 'loads tag links with their proper attributes' do vcr('asset/issue_219') { asset = environment.assets.find(asset_id) - tag = asset.metadata[:tags].first + tag = asset._metadata[:tags].first expect(tag.id).to eq 'mobQa' expect(tag.link_type).to eq 'Tag' } diff --git a/spec/lib/contentful/management/entry_spec.rb b/spec/lib/contentful/management/entry_spec.rb index ba67249..9d9f34b 100644 --- a/spec/lib/contentful/management/entry_spec.rb +++ b/spec/lib/contentful/management/entry_spec.rb @@ -885,14 +885,14 @@ class Contentful::BaseEntry < Contentful::Entry it 'hydrates tags' do vcr('entry/issue_219') { entry = environment.entries.find(entry_id) - expect(entry.metadata[:tags].first).to be_a Contentful::Management::Link + expect(entry._metadata[:tags].first).to be_a Contentful::Management::Link } end it 'loads tag links with their proper attributes' do vcr('entry/issue_219') { entry = environment.entries.find(entry_id) - tag = entry.metadata[:tags].first + tag = entry._metadata[:tags].first expect(tag.id).to eq 'mobQa' expect(tag.link_type).to eq 'Tag' } From dc643f018f5700d8317d92891f2712ce217e1547 Mon Sep 17 00:00:00 2001 From: Bhushan Lodha Date: Mon, 1 Mar 2021 15:15:06 +0530 Subject: [PATCH 2/4] Fixed linting offences --- lib/contentful/management/resource/metadata.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/contentful/management/resource/metadata.rb b/lib/contentful/management/resource/metadata.rb index e0d7baa..6fc597e 100644 --- a/lib/contentful/management/resource/metadata.rb +++ b/lib/contentful/management/resource/metadata.rb @@ -28,10 +28,10 @@ def extract_metadata_from_object!(object) return unless object.key?('metadata') object['metadata'].each do |key, value| @_metadata[key.to_sym] = if key == 'tags' - coerce_tags(value) - else - value - end + coerce_tags(value) + else + value + end end end From a82c1def86e260010e1824f4b501db2bf8b757ec Mon Sep 17 00:00:00 2001 From: Bhushan Lodha Date: Mon, 1 Mar 2021 15:47:38 +0530 Subject: [PATCH 3/4] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe4c35..cd5f261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## Master +* Added support for Tags metadata ## 2.13.1 ### Fixed From 8b863f43d327c3fe73057b49302a2f84a83bf533 Mon Sep 17 00:00:00 2001 From: Bhushan Lodha Date: Tue, 2 Mar 2021 13:17:02 +0530 Subject: [PATCH 4/4] Bump to version 3.0.0 --- CHANGELOG.md | 8 ++++++++ lib/contentful/management/version.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd5f261..9bca3c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,16 @@ # Change Log ## Master + +## 3.0.0 +### Fixed * Added support for Tags metadata +### Changed + +**BREAKING CHANGES**: +* Introduction of new top-level tags `metadata` property in api response. + ## 2.13.1 ### Fixed * Fixed an issue when loading entries or assets that included tags. [#219](https://github.com/contentful/contentful-management.rb/issues/219) diff --git a/lib/contentful/management/version.rb b/lib/contentful/management/version.rb index b50a773..485fd82 100644 --- a/lib/contentful/management/version.rb +++ b/lib/contentful/management/version.rb @@ -3,6 +3,6 @@ module Contentful # Management Namespace module Management # Gem Version - VERSION = '2.13.1'.freeze + VERSION = '3.0.0'.freeze end end