Coder Social home page Coder Social logo

Comments (2)

janko avatar janko commented on May 16, 2024

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.

janko avatar janko commented on May 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.