Last active
December 17, 2015 03:49
-
-
Save rdsubhas/5546071 to your computer and use it in GitHub Desktop.
RapidFTR Addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a marker for all addons, be it ExportTask or anything else | |
# All these will become class methods, and not instance methods | |
module Addon | |
def enabled? | |
@@enabled | |
end | |
def enable | |
@@enabled = true | |
end | |
def disable | |
@@enabled = false | |
end | |
def name | |
# Name of the addon | |
# Planning to make it as an i18n key rather than a string | |
end | |
def implementations | |
descendants.select(&:enabled?) | |
end | |
end | |
# The first addon interface | |
class ExportTask | |
extend Addon | |
# Now all Addon methods are class methods | |
def self.name | |
# Provide name (or i18n key) | |
end | |
def export(children) | |
raise "Not Implemented" | |
end | |
class ExportResult | |
attr_accessor :data, :content_type, :filename | |
end | |
end | |
# The first implementation | |
class CPIMSExportTask < ExportTask | |
def export(children) | |
# Code... | |
end | |
end | |
# The extension has to be enabled in an initializer | |
# config/initializers/addons.rb | |
CPIMSExportTask.enable | |
# Then to get list of Export Tasks, | |
ExportTask.implementations # Will return [CPIMSExportTask] if it was enabled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My alternative recommendation is here: https://gist.github.com/duelinmarkers/5547247