Changeset 4482
- Timestamp:
- 06/21/06 20:40:14 (2 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/validations.rb (modified) (1 diff)
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/aliasing.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/validations.rb
r4348 r4482 219 219 base.class_eval do 220 220 alias_method_chain :save, :validation 221 alias_method_chain :save!, :validation !221 alias_method_chain :save!, :validation 222 222 alias_method_chain :update_attribute, :validation_skipping 223 223 end trunk/activesupport/CHANGELOG
r4455 r4482 1 1 *SVN* 2 3 * alias_method_chain preserves method punctuation so foo, foo?, and foo! may be chained with the same feature. [Jeremy Kemper] 4 Example: 5 alias_method_chain :save!, :validation 6 is equivalent to 7 alias_method :save_without_validation!, :save! 8 alias_method :save!, :save_with_validation! 2 9 3 10 * Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]. Example: trunk/activesupport/lib/active_support/core_ext/module/aliasing.rb
r4430 r4482 10 10 # 11 11 # And both aliases are set up for you. 12 # 13 # Query and bang methods (foo?, foo!) keep the same punctuation: 14 # 15 # alias_method_chain :foo?, :feature 16 # 17 # is equivalent to 18 # 19 # alias_method :foo_without_feature?, :foo? 20 # alias_method :foo?, :foo_without_feature? 21 # 22 # so you can safely chain foo, foo?, and foo! with the same feature. 12 23 def alias_method_chain(target, feature) 13 24 # Strip out punctuation on predicates or bang methods since 14 25 # e.g. target?_without_feature is not a valid method name. 15 aliased_target = target.to_s.sub(/[?!]/, '')16 alias_method "#{aliased_target}_without_#{feature} ", target17 alias_method target, "#{aliased_target}_with_#{feature} "26 aliased_target, punctuation = target.to_s.sub(/([?!])$/, ''), $1 27 alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target 28 alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}" 18 29 end 19 30 end