Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse the InstanceMethods layer from the module pattern #6

Merged
1 commit merged into from
Oct 22, 2010
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions lib/amp-front/dispatch/commands/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module Amp
module Command
module Validations
def self.included(base)
base.__send__(:extend, ClassMethods)
base.__send__(:include, InstanceMethods)
base.extend(ClassMethods)
end
module ClassMethods
def before_blocks
Expand Down Expand Up @@ -153,20 +152,19 @@ def numeric_comparison(value, key_used, constraint)
end
end
end
module InstanceMethods
# Is this a valid set of options and arguments for this command?
def valid?(opts, args)
self.class.before_blocks.all? {|block| block.call(opts, args)}
end
alias_method :run_before, :valid?

def invalid?(opts, args)
!valid?(opts, args)
end

def run_after(opts, args)
self.class.after_blocks.all? {|block| block.call(opts, args)}
end
# Is this a valid set of options and arguments for this command?
def valid?(opts, args)
self.class.before_blocks.all? {|block| block.call(opts, args)}
end
alias_method :run_before, :valid?

def invalid?(opts, args)
!valid?(opts, args)
end

def run_after(opts, args)
self.class.after_blocks.all? {|block| block.call(opts, args)}
end
end
end
Expand Down