Module: Yt::Associations::HasOne
- Included in:
- Models::Base
- Defined in:
- lib/yt/associations/has_one.rb
Overview
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.
Instance Method Summary collapse
Instance Method Details
#has_one(attribute) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/yt/associations/has_one.rb', line 11 def has_one(attribute) require 'yt/associations/has_many' extend Associations::HasMany attributes = attribute.to_s.pluralize has_many attributes define_memoized_method(attribute) { send(attributes).first! } end |