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, :table_meta register_optional_opts :cur_src_pos_file, :table_src_pos_files, :params 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 def source_pos_class self.class::SOURCE_POS_CLASS end end end end