mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
adds more inline docs for dynamically created methods in Active Support
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
class Logger
|
||||
def self.define_around_helper(level)
|
||||
module_eval <<-end_eval
|
||||
def around_#{level}(before_message, after_message, &block)
|
||||
self.#{level}(before_message)
|
||||
return_value = block.call(self)
|
||||
self.#{level}(after_message)
|
||||
return return_value
|
||||
end
|
||||
def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block)
|
||||
self.#{level}(before_message) # self.debug(before_message)
|
||||
return_value = block.call(self) # return_value = block.call(self)
|
||||
self.#{level}(after_message) # self.debug(after_message)
|
||||
return return_value # return return_value
|
||||
end # end
|
||||
end_eval
|
||||
end
|
||||
[:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
|
||||
|
||||
@@ -64,9 +64,9 @@ module ActiveSupport
|
||||
# e.title # => "Megastars"
|
||||
def alias_attribute(new_name, old_name)
|
||||
module_eval <<-STR, __FILE__, __LINE__+1
|
||||
def #{new_name}; self.#{old_name}; end
|
||||
def #{new_name}?; self.#{old_name}?; end
|
||||
def #{new_name}=(v); self.#{old_name} = v; end
|
||||
def #{new_name}; self.#{old_name}; end # def subject; self.title; end
|
||||
def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end
|
||||
def #{new_name}=(v); self.#{old_name} = v; end # def subject=(v); self.title = v; end
|
||||
STR
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,10 +22,10 @@ class Module
|
||||
raise 'Default value or block required' unless !default.nil? || block
|
||||
define_method(sym, block_given? ? block : Proc.new { default })
|
||||
module_eval(<<-EVAL, __FILE__, __LINE__)
|
||||
def #{sym}=(value)
|
||||
class << self; attr_reader :#{sym} end
|
||||
@#{sym} = value
|
||||
end
|
||||
def #{sym}=(value) # def age=(value)
|
||||
class << self; attr_reader :#{sym} end # class << self; attr_reader :age end
|
||||
@#{sym} = value # @age = value
|
||||
end # end
|
||||
EVAL
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,9 +112,9 @@ class Module
|
||||
|
||||
methods.each do |method|
|
||||
module_eval(<<-EOS, "(__DELEGATION__)", 1)
|
||||
def #{prefix}#{method}(*args, &block)
|
||||
#{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)
|
||||
end
|
||||
def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
|
||||
#{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block) # client && client.__send__(:name, *args, &block)
|
||||
end # end
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,11 +26,11 @@ class Module
|
||||
end
|
||||
|
||||
module_eval(<<-EOS, __FILE__, __LINE__)
|
||||
def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
|
||||
#{with}.synchronize do
|
||||
#{aliased_method}_without_synchronization#{punctuation}(*args, &block)
|
||||
end
|
||||
end
|
||||
def #{aliased_method}_with_synchronization#{punctuation}(*args, &block) # def expire_with_synchronization(*args, &block)
|
||||
#{with}.synchronize do # @@lock.synchronize do
|
||||
#{aliased_method}_without_synchronization#{punctuation}(*args, &block) # expire_without_synchronization(*args, &block)
|
||||
end # end
|
||||
end # end
|
||||
EOS
|
||||
|
||||
alias_method_chain method, :synchronization
|
||||
|
||||
Reference in New Issue
Block a user