diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2015-02-14 15:35:47 +0000 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2015-02-14 15:35:47 +0000 |
commit | 95546d493525a79f2da542c7e3fcff6cd5acca73 (patch) | |
tree | 90bd2c1e9be0a1f3767da72d60bf3b519333c791 /activemodel/lib | |
parent | 698afe1173c6501d29b98389204d3ac70aaea910 (diff) | |
parent | 773dd2598d6158a553a33ab638795c128fc1cc8d (diff) | |
download | rails-95546d493525a79f2da542c7e3fcff6cd5acca73.tar.gz rails-95546d493525a79f2da542c7e3fcff6cd5acca73.tar.bz2 rails-95546d493525a79f2da542c7e3fcff6cd5acca73.zip |
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/callbacks.rb | 2 | ||||
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 17 |
2 files changed, 10 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb index 6214802074..2cf39b68fb 100644 --- a/activemodel/lib/active_model/callbacks.rb +++ b/activemodel/lib/active_model/callbacks.rb @@ -49,7 +49,7 @@ module ActiveModel # puts 'block successfully called.' # end # - # You can choose not to have all three callbacks by passing a hash to the + # You can choose to have only specific callbacks by passing a hash to the # +define_model_callbacks+ method. # # define_model_callbacks :create, only: [:after, :before] diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index ca5dac272f..c03e5fac79 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -118,7 +118,7 @@ module ActiveModel attribute_method_affix prefix: 'restore_', suffix: '!' end - # Returns +true+ if any attribute have unsaved changes, +false+ otherwise. + # Returns +true+ if any of the attributes have unsaved changes, +false+ otherwise. # # person.changed? # => false # person.name = 'bob' @@ -166,7 +166,7 @@ module ActiveModel @changed_attributes ||= ActiveSupport::HashWithIndifferentAccess.new end - # Handle <tt>*_changed?</tt> for +method_missing+. + # Handles <tt>*_changed?</tt> for +method_missing+. def attribute_changed?(attr, options = {}) #:nodoc: result = changes_include?(attr) result &&= options[:to] == __send__(attr) if options.key?(:to) @@ -174,7 +174,7 @@ module ActiveModel result end - # Handle <tt>*_was</tt> for +method_missing+. + # Handles <tt>*_was</tt> for +method_missing+. def attribute_was(attr) # :nodoc: attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr) end @@ -186,6 +186,7 @@ module ActiveModel private + # Returns +true+ if attr_name is changed, +false+ otherwise. def changes_include?(attr_name) attributes_changed_by_setter.include?(attr_name) end @@ -197,18 +198,18 @@ module ActiveModel @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new end - # Clear all dirty data: current changes and previous changes. + # Clears all dirty data: current changes and previous changes. def clear_changes_information # :doc: @previously_changed = ActiveSupport::HashWithIndifferentAccess.new @changed_attributes = ActiveSupport::HashWithIndifferentAccess.new end - # Handle <tt>*_change</tt> for +method_missing+. + # Handles <tt>*_change</tt> for +method_missing+. def attribute_change(attr) [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) end - # Handle <tt>*_will_change!</tt> for +method_missing+. + # Handles <tt>*_will_change!</tt> for +method_missing+. def attribute_will_change!(attr) return if attribute_changed?(attr) @@ -221,7 +222,7 @@ module ActiveModel set_attribute_was(attr, value) end - # Handle <tt>restore_*!</tt> for +method_missing+. + # Handles <tt>restore_*!</tt> for +method_missing+. def restore_attribute!(attr) if attribute_changed?(attr) __send__("#{attr}=", changed_attributes[attr]) @@ -230,7 +231,7 @@ module ActiveModel end # This is necessary because `changed_attributes` might be overridden in - # other implemntations (e.g. in `ActiveRecord`) + # other implementations (e.g. in `ActiveRecord`) alias_method :attributes_changed_by_setter, :changed_attributes # :nodoc: # Force an attribute to have a particular "before" value |