Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from jayferd/master

Using `#define_method` for fewer surprises
  • Loading branch information...
commit 20dde0bda8bd7ffdf8c9c9a4ff8b68f4d1ecdb07 2 parents 58c16b1 + bce6e58
@karmajunkie karmajunkie authored
Showing with 7 additions and 5 deletions.
  1. +7 −5 lib/imperator/command.rb
View
12 lib/imperator/command.rb
@@ -15,7 +15,7 @@ class << self
end
def self.action(&block)
- @perform_block = block
+ define_method(:action, &block)
end
alias_method :params, :attributes
@@ -61,11 +61,13 @@ def perform!
self.perform
end
+ # @abstract
+ def action
+ raise NoMethodError.new("Please define #action for #{self.class.name}")
+ end
+
def perform
- raise "You need to define the perform block for #{self.class.name}" unless self.class.perform_block
- run_callbacks :perform do
- self.instance_exec(&self.class.perform_block)
- end
+ run_callbacks(:perform) { action }
end
def method_missing(method, *args)
Please sign in to comment.
Something went wrong with that request. Please try again.