Permalink
Browse files

added method factory

  • Loading branch information...
1 parent d64c9d0 commit f8f2740d4ea4ca98404b026e716b4bbcba057a92 @kristianmandrup committed Aug 2, 2012
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/imperator/command/method_factory.rb
View
15 lib/imperator/command/method_factory.rb
@@ -0,0 +1,15 @@
+class Imperator::Command
+ module MethodFactory
+ def command_method command, options = {}
+ define_method "#{command}_command" do
+ instance_var = "@#{command}_command"
+ unless instance_variable_get(instance_var)
+ clazz = "#{command.to_s.camelize}Command".constantize
+ instance_variable_set instance_var, clazz.new options.merge(initiator: self)
+ end
+ end
+ end
+
+ extend self
+ end
+end

0 comments on commit f8f2740

Please sign in to comment.