Changeset 4653
- Timestamp:
- 08/03/06 18:47:43 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/date/conversions.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/aliasing.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/module (added)
- trunk/activesupport/test/core_ext/module_test.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/module/attribute_aliasing_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4647 r4653 1 1 *SVN* 2 3 * Added Module#alias_attribute [Jamis/DHH]. Example: 4 5 class Content < ActiveRecord::Base 6 # has a title attribute 7 end 8 9 class Email < ActiveRecord::Base 10 alias_attribute :subject, :title 11 end 12 13 e = Email.find(1) 14 e.title # => "Superstars" 15 e.subject # => "Superstars" 16 e.subject? # => true 17 e.subject = "Megastars" 18 e.title # => "Megastars" 2 19 3 20 * Deprecation: easier to work with warning behavior as procs; default behaviors for each environment so users needn't update env.rb; and testing pleasure with assert_deprecated, assert_not_deprecated. [Jeremy Kemper] trunk/activesupport/lib/active_support/core_ext/date/conversions.rb
r3952 r4653 26 26 ::Time.send(form, year, month, day) 27 27 end 28 29 alias :xmlschema :to_s 28 29 def xmlschema 30 to_time.xmlschema 31 end 30 32 end 31 33 end trunk/activesupport/lib/active_support/core_ext/module/aliasing.rb
r4534 r4653 28 28 alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}" 29 29 end 30 31 # Allows you to make aliases for attributes, which includes 32 # getter, setter, and query methods. 33 # 34 # Example: 35 # 36 # class Content < ActiveRecord::Base 37 # # has a title attribute 38 # end 39 # 40 # class Email < ActiveRecord::Base 41 # alias_attribute :subject, :title 42 # end 43 # 44 # e = Email.find(1) 45 # e.title # => "Superstars" 46 # e.subject # => "Superstars" 47 # e.subject? # => true 48 # e.subject = "Megastars" 49 # e.title # => "Megastars" 50 def alias_attribute(new_name, old_name) 51 module_eval <<-STR, __FILE__, __LINE__+1 52 def #{new_name}; #{old_name}; end 53 def #{new_name}?; #{old_name}?; end 54 def #{new_name}=(v); self.#{old_name} = v; end 55 STR 56 end 30 57 end trunk/activesupport/test/core_ext/module_test.rb
r4595 r4653 118 118 119 119 class MethodAliasingTest < Test::Unit::TestCase 120 121 120 def setup 122 121 Object.const_set(:FooClassWithBarMethod, Class.new)