module Flydata module PluginSupport class Context def self.mandatory_opts @mandatory_opts ||= [] end def self.optional_opts @optional_opts ||= [] end def self.register_mandatory_opts(*opts) @mandatory_opts ||= [] opts.each {|opt| @mandatory_opts << opt.to_sym attr_accessor opt } nil end def self.register_optional_opts(*opts) @optional_opts ||= [] opts.each {|opt| @optional_opts << opt.to_sym attr_accessor opt } nil end register_mandatory_opts :tables, :tag, :sync_fm, :omit_events, :table_revs register_optional_opts :current_binlog_file def initialize(opts) missing_opts = self.class.mandatory_opts - opts.keys unless (missing_opts.empty?) raise "Mandatory option(s) are missing: #{missing_opts.join(', ')}" end opts.each do |k, v| self.instance_variable_set(:"@#{k}", v) end end end end end