module Yt::Associations::HasMany

@private Associations are a set of macro-like class methods to express relationship between YouTube resources like “Channel has many Videos” or “Account has one Id”. They are inspired by ActiveRecord::Associations.

Public Instance Methods

has_many(attributes) click to toggle source

@example Adds the videos method to the Channel resource.

class Channel < Resource
  has_many :videos
end
# File lib/yt/associations/has_many.rb, line 12
def has_many(attributes)
  require 'active_support' # does not load anything by default
  require 'active_support/core_ext/string/inflections' # for camelize ...
  require "yt/collections/#{attributes}"
  collection_name = attributes.to_s.sub(/.*\./, '').camelize.pluralize
  collection = "Yt::Collections::#{collection_name}".constantize
  define_memoized_method(attributes) { collection.of self }
end