Guest User

Untitled

a guest
Jun 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. require 'yaml'
  2.  
  3. class Plugin
  4. class << self; attr :plugins; end
  5. @plugins = []
  6.  
  7. def initialize opts = nil
  8. if opts
  9. opts.each do |k,v|
  10. instance_variable_set('@' + k, v)
  11. end
  12. end
  13. end
  14.  
  15. def self.generate path, opts = nil
  16. Dir["#{path}/**/*.yml"].each do |file|
  17. filebase = File.basename(file, '.yml')
  18. if opts.has_value?(filebase) || opts.has_key?(filebase.to_sym)
  19. options = YAML::load( File.open(file))
  20.  
  21. @plugins << klass = Object.const_set(filebase.capitalize, Class.new(Plugin))
  22.  
  23. klass.module_eval do
  24. @@options = options
  25. end
  26. end
  27. end
  28. end
  29.  
  30. def self.options
  31. @@options
  32. end
  33. end
  34.  
  35. Plugin::generate('.', :name => "selman")
  36. p Plugin.plugins
  37. p Name.options
Add Comment
Please, Sign In to add comment