Skip to content

Instantly share code, notes, and snippets.

@rdsubhas
Last active December 17, 2015 03:49
Show Gist options
  • Save rdsubhas/5546071 to your computer and use it in GitHub Desktop.
Save rdsubhas/5546071 to your computer and use it in GitHub Desktop.
RapidFTR Addon
# 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
@duelinmarkers
Copy link

My alternative recommendation is here: https://gist.github.com/duelinmarkers/5547247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment