Skip to content

Commit

Permalink
Merge pull request #222 from rubydog/bhushan/tags-metadata
Browse files Browse the repository at this point in the history
server tags metadata as _metadata
  • Loading branch information
ruderngespra authored Mar 2, 2021
2 parents 8714f82 + 8b863f4 commit 3310792
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## 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)
Expand Down
22 changes: 9 additions & 13 deletions lib/contentful/management/resource/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,11 +27,11 @@ 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'
coerce_tags(value)
else
value
end
@_metadata[key.to_sym] = if key == 'tags'
coerce_tags(value)
else
value
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/contentful/management/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module Contentful
# Management Namespace
module Management
# Gem Version
VERSION = '2.13.1'.freeze
VERSION = '3.0.0'.freeze
end
end
4 changes: 2 additions & 2 deletions spec/lib/contentful/management/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/contentful/management/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 3310792

Please sign in to comment.