Last active
December 20, 2016 02:14
-
-
Save thiagoa/f20613faf98d1c39fe8c1a41bee9fae5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Imageable < Module | |
def initialize(has_one: %i(main_image)) | |
has_one.each { |image_kind| define_image_getter(image_kind) } | |
end | |
private | |
def included(model_class) | |
model_class.has_many :images | |
end | |
def define_image_getter(image_kind) | |
define_method image_kind do | |
images.find_by(kind: image_kind) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment