From 878194b468d10c013d9b2051b2169cd554f6c795 Mon Sep 17 00:00:00 2001 From: claudiob Date: Tue, 4 Apr 2017 09:51:13 -0700 Subject: [PATCH] Video#tags should return [] if video has no tags --- CHANGELOG.md | 5 +++++ lib/yt/core/version.rb | 2 +- lib/yt/resource.rb | 2 +- lib/yt/video.rb | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d40e9ba..6e67f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ For more information about changelogs, check [Keep a Changelog](http://keepachangelog.com) and [Vandamme](http://tech-angels.github.io/vandamme). +## 0.1.1 - 2017-04-04 + +* [ENHANCEMENT] Add :defaults to `has_attribute` +* [BUGFIX] Video#tags returns `[]` and not `nil` when a video has no tags + ## 0.1.0 - 2017-04-03 * [FEATURE] Extracted first classes from Yt diff --git a/lib/yt/core/version.rb b/lib/yt/core/version.rb index a473007..e793771 100644 --- a/lib/yt/core/version.rb +++ b/lib/yt/core/version.rb @@ -3,6 +3,6 @@ module Yt module Core # @return [String] the SemVer-compatible gem version. # @see http://semver.org - VERSION = '0.1.0' + VERSION = '0.1.1' end end diff --git a/lib/yt/resource.rb b/lib/yt/resource.rb index d19ccf4..59763f1 100644 --- a/lib/yt/resource.rb +++ b/lib/yt/resource.rb @@ -52,7 +52,7 @@ def self.has_attribute(name, options = {}, &block) part = keys.shift value = @data[part] || fetch_part(part) keys.each{|key| value = value[camelize key]} - value = type_cast value, options[:type] + value = type_cast (value || options[:default]), options[:type] block_given? ? instance_exec(value, &block) : value end end diff --git a/lib/yt/video.rb b/lib/yt/video.rb index dbcde5b..7db3339 100644 --- a/lib/yt/video.rb +++ b/lib/yt/video.rb @@ -34,7 +34,7 @@ class Video < Resource # @!attribute [r] tags # @return [Array] the list of tags associated with the video. - has_attribute :tags, in: :snippet + has_attribute :tags, in: :snippet, default: [] # @!attribute [r] category_id # @return [Integer] the ID of the associated YouTube video category.