lib/exporter/configuration.rb in exporter-0.0.3 vs lib/exporter/configuration.rb in exporter-0.1.0
- old
+ new
@@ -1,19 +1,34 @@
module Exporter
class Configuration
+
def initialize
@exporters = Hash.new
end
def register(data_type, export_type, exporter)
- @exporters[data_type] = {export_type => exporter}
+ if @exporters[data_type].nil?
+ @exporters[data_type] = {export_type => exporter}
+ else
+ @exporters[data_type][export_type] = exporter
+ end
end
- def can_export?(data_type, export_type)
- @exporters[data_type] && @exporters[data_type][export_type]
+ def index(data, default_value, method)
+ @exporters.keys.each do |key|
+ return method.call(key) if data.kind_of?(key)
+ end
+ default_value
end
- def exporter(data_type, export_type)
- can_export?(data_type, export_type) ? @exporters[data_type][export_type] : nil
+ def can_export?(data, export_type)
+ can_export_proc = Proc.new{|key| @exporters[key][export_type].present?}
+ index(data, false, can_export_proc)
end
+
+ def exporter(data, export_type)
+ exporter_proc = Proc.new {|key| @exporters[key][export_type]}
+ index(data, nil, exporter_proc)
+ end
+
end
-end
\ No newline at end of file
+end