class AppleMusic::Resource

developer.apple.com/documentation/applemusicapi/resource

Constants

RESOURCE_MAP

Attributes

attributes_model[RW]
relationships_model[RW]
attributes[R]
href[R]
id[R]
relationships[R]
type[R]

Public Class Methods

build(props) click to toggle source
# File lib/apple_music/resource.rb, line 25
def build(props)
  class_name = RESOURCE_MAP[props['type']] || raise(InvalidTypeError, "#{props['type']} type is undefined.")
  const_get(class_name).new(props)
end
new(props = {}) click to toggle source
# File lib/apple_music/resource.rb, line 33
def initialize(props = {})
  @href = props['href']
  @id = props['id']
  @type = props['type']
  @attributes = self.class.attributes_model.new(props['attributes']) if props['attributes']
  @relationships = self.class.relationships_model.new(props['relationships']) if props['relationships']
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/apple_music/resource.rb, line 43
def method_missing(name, *args, &block)
  if attributes.respond_to?(name)
    attributes.send(name, *args, &block)
  elsif relationships.respond_to?(name)
    relationships.send(name, *args, &block)
  else
    super
  end
end
respond_to_missing?(name, include_private = false) click to toggle source
# File lib/apple_music/resource.rb, line 53
def respond_to_missing?(name, include_private = false)
  attributes.respond_to?(name, include_private) || relationships.respond_to?(name, include_private)
end