module NCipher::ArgumentValidation
Public Class Methods
around_alias(owner, new_name, old_name)
click to toggle source
# File lib/n_cipher/argument_validation.rb, line 75 def around_alias(owner, new_name, old_name) owner.class_eval do private(old_name) alias_method new_name, old_name end end
define_proxy_method(owner, name)
click to toggle source
# File lib/n_cipher/argument_validation.rb, line 56 def define_proxy_method(owner, name) owner.class_eval do define_method(name) do |*args, &block| validations = ::NCipher::ArgumentValidation .validations .values_at(self.class, self.singleton_class) .compact .each_with_object({}) {|orig_h,rtn_h| rtn_h.merge!(orig_h) } validations["__#{name}__"].each do |pattern| # ブロックをインスタンスのコンテキストで評価 raise(pattern[:exception]) unless self.instance_exec(*args, block, &pattern[:validation]) end __send__("__#{name}__", *args, &block) end end end
included(klass)
click to toggle source
# File lib/n_cipher/argument_validation.rb, line 5 def self.included(klass) klass.extend(ClassMethod) klass.extend(InheritValidation) Method.send(:include, MonkeyPatchToMethodClass) end
store_validation(owner, method_name, validation, exception)
click to toggle source
# File lib/n_cipher/argument_validation.rb, line 47 def store_validation(owner, method_name, validation, exception) @@validations[owner] ||= {} @@validations[owner][method_name] ||= [] @@validations[owner][method_name] << { :validation => validation, :exception => exception } end
validations()
click to toggle source
# File lib/n_cipher/argument_validation.rb, line 82 def validations @@validations end