Skip to content

Commit

Permalink
Fix .select to always include required part
Browse files Browse the repository at this point in the history
For instance if `channel = Yt::Channel.new(id: ..).select(:snippet)`
and then I ask for `channel.view_count`, the `:statistics` part should
be added to the request even if it was not specified at the beginning.
  • Loading branch information
claudiob committed Apr 6, 2017
1 parent 7cdabaa commit 6ac0e35
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ For more information about changelogs, check
[Keep a Changelog](http://keepachangelog.com) and
[Vandamme](http://tech-angels.github.io/vandamme).

## 0.1.2 - 2017-04-06

* [BUGFIX] Fix cases like `channel.select(:snippet).view_count` where attribute does not belong to any selected part.

## 0.1.1 - 2017-04-04

* [ENHANCEMENT] Add :defaults to `has_attribute`
Expand Down
2 changes: 1 addition & 1 deletion lib/yt/core/version.rb
Expand Up @@ -3,6 +3,6 @@ module Yt
module Core
# @return [String] the SemVer-compatible gem version.
# @see http://semver.org
VERSION = '0.1.1'
VERSION = '0.1.2'
end
end
4 changes: 2 additions & 2 deletions lib/yt/resource.rb
Expand Up @@ -6,7 +6,7 @@ class Resource
# @option data [String] :id The unique ID of a YouTube resource.
def initialize(data = {})
@data = data
@selected_data_parts = nil
@selected_data_parts = []
end

# @return [String] the resource’s unique ID.
Expand Down Expand Up @@ -65,7 +65,7 @@ def fetch_part(required_part)
fetch resources_path, resource_params(options)
end

parts = @selected_data_parts || [required_part]
parts = (@selected_data_parts + [required_part]).uniq
if (resource = resources.select(*parts).first)
parts.each{|part| @data[part] = resource.data[part]}
@data[required_part]
Expand Down

0 comments on commit 6ac0e35

Please sign in to comment.