Skip to content

Instantly share code, notes, and snippets.

@selman
Created November 3, 2010 00:06
Show Gist options
  • Save selman/660559 to your computer and use it in GitHub Desktop.
Save selman/660559 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment