Hello folks.
I am refactoring a simple CMS, and looking to implement a simple
internal plugin architecture.
I have a MenuItem class. By default, menu items can be, say, ‘article’
or ‘sitemap’, or ‘newsroll’. I want to implement a hook to which my
modules can plug, so I will be able to add other tipologies (like
“catalog”, “gallery” or whatever) through modules, which are aptly
structured plugins.
Presently, I have something like this:
class MenuItem < ActiveRecord::Base
belongs_to :article
@tipologies = Array.new
@tipologies.push("article","sitemap")
def self.tipologies
return @tipologies
end
def self.addTipology(item)
@tipologies.push(item)
end
end
I have been able to add an item to @typologies through a plugin, with
this init.rb
ActionController::Base.send :include, Tipeadder
And this is the main plugin code (obviously I am just sketching here):
# Tipeadder.rb
module Tipeadder
MenuItem.addTipology("cane")
MenuItem.addTipology("gatto")
end
Yet the type is added only when the app is first loaded, then it gets
lost.
I am a also bit lost here. I have been using plugin architectures for
ages in Wordpress development, but never implemented one, so i am not
sure I am going the right way.
Have you go some general advice on the procedure I should follow? Which
is the best and most ruby-like way to do this?
Thanks,
Davide