Skip to content

Instantly share code, notes, and snippets.

@Morozzzko
Created November 18, 2020 12:02
Show Gist options
  • Select an option

  • Save Morozzzko/b5dd393a04264377504737fc614c2e1e to your computer and use it in GitHub Desktop.

Select an option

Save Morozzzko/b5dd393a04264377504737fc614c2e1e to your computer and use it in GitHub Desktop.
Recipe: List all Shrine attachments & models. Double dash (--) in file names is a directory separator (/). Run your test suite to load all models and print them afterwards
require 'shrine/plugins/list_attachments'
Shrine.plugin :list_attachments
# frozen_string_literal: true
class Shrine
module Plugins
module ListAttachments
Registry = {} # rubocop:disable Style/MutableConstant
module AttachmentMethods
def included(base)
Registry[base] ||= []
Registry[base] << attachment_name
end
end
end
register_plugin(:list_attachments, ListAttachments)
end
end
RSpec.configure do |config|
...
config.after(:suite) do
Shrine::Plugins::ListAttachments::Registry.each do |base, names|
names.each do |name|
$stdout.puts "#{base.name}##{name}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment