Module: Ape::Util::ClassMethods
- Defined in:
- lib/ape/util.rb
Instance Method Summary collapse
-
#resolve_plugin(key, dir, suffix, drop_underlines = false) ⇒ Object
Resolve extensions into the lib directory or into the ape home directory.
Instance Method Details
#resolve_plugin(key, dir, suffix, drop_underlines = false) ⇒ Object
Resolve extensions into the lib directory or into the ape home directory. These extensions could be validators, resolvers or samples.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ape/util.rb', line 54 def resolve_plugin(key, dir, suffix, drop_underlines = false) [File.dirname(__FILE__), ::Ape.home].each do |path| Dir[File.join(path, "#{dir}/*.rb")].each do |file| require file plugin_name = file.gsub(/(.+\/#{dir}\/)(.+)(_#{suffix}.rb)/, '\2') plugin_name.gsub!(/_/, '') if drop_underlines plugin_class = file.gsub(/(.+\/#{dir}\/)(.+)(.rb)/, '\2').gsub(/(^|_)(.)/) { $2.upcase } if (key.to_s.strip.downcase.include?(plugin_name)) return eval("#{plugin_class}.new", binding, __FILE__, __LINE__) end end end return nil end |