Module: Hallon::Linkable::ClassMethods
- Defined in:
- lib/hallon/linkable.rb
Overview
ClassMethods adds #from_link
and #to_link
DSL methods, which
essentially are convenience methods for defining the way to convert
a link to a pointer of a given Spotify object type.
Instance Method Summary collapse
-
#from_link(as_object, &block) ⇒ Object
Defines
#from_link
, used in converting a link to a pointer. -
#to_link(cmethod) ⇒ Link?
Defines
#to_link
method, used in converting the object to a Hallon::Link.
Instance Method Details
#from_link(method_name) ⇒ Object #from_link(type) {|link, *args| ... } ⇒ Object
Note:
Private API. You probably do not need to care about this method.
Defines #from_link
, used in converting a link to a pointer. You
can either pass it a method_name
, or a type
and a block.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hallon/linkable.rb', line 67 def from_link(as_object, &block) block ||= Spotify.method(:"link_#{as_object}") type = as_object.to_s[/^(as_)?([^_]+)/, 2].to_sym define_method(:from_link) do |link, *args| unless link.is_a?(Spotify::Link) link = Link.new(link).pointer(type) end instance_exec(link, *args, &block) end private :from_link end |
#to_link(cmethod) ⇒ Link?
Defines #to_link
method, used in converting the object to a Hallon::Link.
98 99 100 101 102 103 |
# File 'lib/hallon/linkable.rb', line 98 def to_link(cmethod) define_method(:to_link) do |*args| link = Spotify.__send__(:"link_create_#{cmethod}", pointer, *args) Link.from(link) end end |