Permalink
Browse files

Added dynamic matchers for exporting types.

  • Loading branch information...
1 parent d4d3fc3 commit e1189230841b5bb92025bb14c93964f39fe67396 @murek murek committed Dec 30, 2010
Showing with 49 additions and 2 deletions.
  1. +26 −0 lib/dynamic_exporter_match.rb
  2. +23 −2 lib/exportable.rb
@@ -0,0 +1,26 @@
+class DynamicExporterMatch
+
+ attr_reader :exporter
+
+ def self.match(method)
+ df_match = self.new(method)
+ df_match.finder ? df_match : nil
+ end
+
+ def initialize(method)
+ case method.to_s
+ when /^to_(csv|pdf|html|html)$/
+ @exporter = :csv if $1 == 'csv'
+ @exporter = :pdf if $1 == 'pdf'
+ @exporter = :html if $1 == 'html'
+ @exporter = :txt if $1 == 'txt'
+ else
+ @exporter = nil
+ end
+ end
+
+ def exporter?
+ !@exporter.nil?
+ end
+
+end
View
@@ -1,5 +1,11 @@
# Exportable
module Exportable
+
+ # Generic Exporatble exception class
+ class ExportableError < StandardError; end
+ # Raised when Exportable cannot data to a given type
+ class UnkownType < StandardError; end
+
def self.included(base)
base.extend ClassMethods
@@ -16,9 +22,24 @@ def acts_as_exportable(options = {}, &extension)
end
end
-
+
+ # Contains methods available as singleton class methods to
+ # any ActiveRecord model that calls <tt>acts_as_exportable</tt>
module SingletonMethods
-
+ # intercept calls for exporting methods
+ def method_missing(method_id, *args, &block)
+ method_name = method_id.to_s
+ if match = DynamicExporterMatch.match(method_name)
+ if matcher.exporter?
+ exporter = match.exporter
+
+
+ end
+ end
+
+ options = args.extract_options!
+
+ end
end
end

0 comments on commit e118923

Please sign in to comment.