Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'yaml'
- class Plugin
- class << self; attr :plugins; end
- @plugins = []
- def initialize opts = nil
- if opts
- opts.each do |k,v|
- instance_variable_set('@' + k, v)
- end
- end
- end
- def self.generate path, opts = nil
- Dir["#{path}/**/*.yml"].each do |file|
- filebase = File.basename(file, '.yml')
- if opts.has_value?(filebase) || opts.has_key?(filebase.to_sym)
- options = YAML::load( File.open(file))
- @plugins << klass = Object.const_set(filebase.capitalize, Class.new(Plugin))
- klass.module_eval do
- @@options = options
- end
- end
- end
- end
- def self.options
- @@options
- end
- end
- Plugin::generate('.', :name => "selman")
- p Plugin.plugins
- p Name.options
Add Comment
Please, Sign In to add comment