Created
November 18, 2020 12:02
-
-
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
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
| require 'shrine/plugins/list_attachments' | |
| Shrine.plugin :list_attachments |
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
| # 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 |
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
| 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