Skip to content

Instantly share code, notes, and snippets.

@TeWu
Last active September 16, 2016 08:57
Show Gist options
  • Save TeWu/f9f285408ab5ee2dafdde53e11da3028 to your computer and use it in GitHub Desktop.
Save TeWu/f9f285408ab5ee2dafdde53e11da3028 to your computer and use it in GitHub Desktop.
Refactor or not to refactor - that is the question: Whether 'tis nobler in the mind to suffer. The slings and arrows of outrageous fortune. Or to take arms against a sea of troubles. And by opposing end them.
def prev_photo_url(album, photo, **options)
prev_photo_id = album.prev_photo_id(photo)
album_photo_url album, prev_photo_id, options if prev_photo_id
end
def prev_photo_path (album, photo, **options)
prev_photo_url(album, photo, {only_path: true}.merge!(options))
end
def next_photo_url(album, photo, **options)
next_photo_id = album.next_photo_id(photo)
album_photo_url album, next_photo_id, options if next_photo_id
end
def next_photo_path (album, photo, **options)
next_photo_url(album, photo, {only_path: true}.merge!(options))
end
[:path, :url].each do |variant|
define_method "prev_photo_#{variant}" do |album, photo, **options|
prev_photo_id = album.prev_photo_id(photo)
send("album_photo_#{variant}", album, prev_photo_id, options) if prev_photo_id
end
define_method "next_photo_#{variant}" do |album, photo, **options|
next_photo_id = album.next_photo_id(photo)
send("album_photo_#{variant}", album, next_photo_id, options) if next_photo_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment