Class: Amp::Plugins::Base
- Extended by:
- ModuleExtensions
- Defined in:
- lib/amp-front/plugins/base.rb
Class Method Summary collapse
-
.all_plugins ⇒ Object
This tracks all subclasses (and subclasses of subclasses, etc).
-
.create(name, superclass = Amp::Plugins::Base) ⇒ Object
Creates a Plugin subclass with the given name.
-
.inherited(klass) ⇒ Object
When a Plugin subclass is subclassed, store the subclass and inform the next superclass up the inheritance hierarchy.
- .load_rubygems_plugins ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Base
constructor
Generic initialization all plugins perform.
- #inspect ⇒ Object
- #load! ⇒ Object
- #module ⇒ Object
Methods included from ModuleExtensions
cattr_accessor, cattr_accessor_with_default, cattr_get_and_setter, cattr_reader, cattr_writer, singleton_class
Constructor Details
#initialize(opts = {}) ⇒ Base
Generic initialization all plugins perform. Takes an options hash.
71 72 |
# File 'lib/amp-front/plugins/base.rb', line 71 def initialize(opts={}) end |
Class Method Details
.all_plugins ⇒ Object
This tracks all subclasses (and subclasses of subclasses, etc). Plus, this method is inherited, so Wool::Plugins::Git.all_subclasses will have all subclasses of Wool::Plugins::Git!
25 26 27 |
# File 'lib/amp-front/plugins/base.rb', line 25 def self.all_plugins @all_plugins ||= [self] end |
.create(name, superclass = Amp::Plugins::Base) ⇒ Object
Creates a Plugin subclass with the given name. Also allows specifying the superclass to use.
Reopens existing plugins if they already exist, for user customization.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/amp-front/plugins/base.rb', line 44 def self.create(name, superclass=Amp::Plugins::Base) unless (name = name.to_s) && name.size > 0 raise ArgumentError.new('name must be a non-empty string') end name = name[0,1].upcase + name[1..-1] klass = nil Amp::Plugins.class_eval do if const_defined?(name) klass = const_get(name) else klass = Class.new(superclass) const_set(name, klass) # So the class has a name end yield klass if block_given? end klass end |
.inherited(klass) ⇒ Object
When a Plugin subclass is subclassed, store the subclass and inform the next superclass up the inheritance hierarchy.
31 32 33 34 35 36 37 38 |
# File 'lib/amp-front/plugins/base.rb', line 31 def self.inherited(klass) self.all_plugins << klass next_klass = self.superclass while next_klass != Amp::Plugins::Base.superclass next_klass.send(:inherited, klass) next_klass = next_klass.superclass end end |
.load_rubygems_plugins ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/amp-front/plugins/base.rb', line 62 def self.load_rubygems_plugins require 'rubygems' files = Gem.find_files('amp_plugin.rb') files.each do |file| load file end end |
Instance Method Details
#inspect ⇒ Object
74 75 76 |
# File 'lib/amp-front/plugins/base.rb', line 74 def inspect "#<Amp::Plugin::#{self.module} #{self.class.name} by #{self.class.}>" end |
#load! ⇒ Object
82 83 84 |
# File 'lib/amp-front/plugins/base.rb', line 82 def load! # Subclasses should implement this. end |
#module ⇒ Object
78 79 80 |
# File 'lib/amp-front/plugins/base.rb', line 78 def module self.class.module || self.class.name end |