Comments (2)
Thanks for raising this concern. I definitely agree with you that const_defined?
is better than defined?
, I haven't thought about that. I will push a fix shortly.
from shrine.
Now that I think about it more, this case would only happen if the plugin is defined on top-level (instead of under Shrine::Plugins
which is the convention), and only if one of these constants are defined on top-level, which is extremely unlikely. And what you're proposing is changing from
def plugin(plugin, *args, &block)
plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)
self.include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
self.extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
self::UploadedFile.include(plugin::FileMethods) if defined?(plugin::FileMethods)
self::UploadedFile.extend(plugin::FileClassMethods) if defined?(plugin::FileClassMethods)
self::Attachment.include(plugin::AttachmentMethods) if defined?(plugin::AttachmentMethods)
self::Attachment.extend(plugin::AttachmentClassMethods) if defined?(plugin::AttachmentClassMethods)
self::Attacher.include(plugin::AttacherMethods) if defined?(plugin::AttacherMethods)
self::Attacher.extend(plugin::AttacherClassMethods) if defined?(plugin::AttacherClassMethods)
plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
nil
end
to
def plugin(plugin, *args, &block)
plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)
self.include(plugin::InstanceMethods) if plugin.const_defined?(:InstanceMethods, false)
self.extend(plugin::ClassMethods) if plugin.const_defined?(:ClassMethods, false)
self::UploadedFile.include(plugin::FileMethods) if plugin.const_defined?(:FileMethods, false)
self::UploadedFile.extend(plugin::FileClassMethods) if plugin.const_defined?(:FileClassMethods, false)
self::Attachment.include(plugin::AttachmentMethods) if plugin.const_defined?(:AttachmentMethods, false)
self::Attachment.extend(plugin::AttachmentClassMethods) if plugin.const_defined?(:AttachmentClassMethods, false)
self::Attacher.include(plugin::AttacherMethods) if plugin.const_defined?(:AttacherMethods, false)
self::Attacher.extend(plugin::AttacherClassMethods) if plugin.const_defined?(:AttacherClassMethods, false)
plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
nil
end
The const_defined?
syntax is much more unreadable to me, especially with the second argument, and for the reasons stated I don't think it's worth the tradeoff.
from shrine.
Related Issues (20)
- Download Endpoint returns http 500 for invalid urls
- 308 redirect HOT 1
- Plugin: "remove_invalid" doesn't clear _data column. HOT 5
- Shrine upload_endpoint on Sinatra 400 Bad Request HOT 2
- [Bug]: Error occurred when attempting to extract image dimensions: #<FastImage::UnknownImageType: FastImage::UnknownImageType> HOT 8
- [Bug]: Corruption of downloaded files when using `net-protocol v0.2.0` HOT 16
- [Bug]: Fix for bytesize on Array doesn't work when aws-core is installed from debian HOT 5
- [Bug]: remove_attachment error with ruby 3.2 HOT 2
- [Bug]: upload_options plugin moves file from store to cache HOT 2
- [Bug]: NoMethodError (undefined method 'bucket' for nil:NilClass) HOT 1
- [Bug]: no _dump_data is defined for class Proc (Shrine with Rails Cache) HOT 1
- [Bug]: `create_derivatives` uploads files already in the store HOT 2
- Website search broken after migrating to Docusaurus v2
- Support retries with remote_url HOT 1
- Unpermitted parameter: :images with dropzonejs HOT 4
- Specifying host: with plugin :url_options has no effect on the returned URL HOT 5
- Disabling cache is tricky HOT 2
- [Bug] File not promoted on permanent storage if reload the model inside a transaction HOT 4
- Using Shrine with Cloudflare R2 causes error Aws::S3::Errors::NotImplemented - x-amz-tagging HOT 5
- Documentation for `image_url` options HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shrine.