-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
I find EmbedlyObject's behaviour to return nil for non-existent members convenient. It would be even more convenient if (hash and) array members would return an object that behaves in a similar way, so that for example response.images.first.name doesn't give an error when there are no associated images. I would have expected response.images to be something like an EmbedlyObject.
Right now I'm wrapping the response in an object containing something like
class MyEmbedly < SimpleDelegator
def initialize(url)
super(url)
end
def images
(super || []).map &OpenStruct.method(:new)
end
private
def data(url)
@embedly ||= Embedly::API.new key: ENV['EMBEDLY_KEY']
@data ||= @embedly.extract(url: url).first
end
endbut believe it could better be solved here.
Metadata
Metadata
Assignees
Labels
No labels