aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-04-25 15:43:29 +0200
committerOscar Del Ben <info@oscardelben.com>2012-04-25 15:43:29 +0200
commit4179141a012c84afa4756aa565aca3a07e4693fa (patch)
treebaf0a7c97fda49455408ee86b73272911acd14f8 /activemodel/lib/active_model
parentee4e7125a61c703332a8d591a0aee917ba828e62 (diff)
parent4a3ce153f1e05c9c590e9ee74e818649336d929f (diff)
downloadrails-4179141a012c84afa4756aa565aca3a07e4693fa.tar.gz
rails-4179141a012c84afa4756aa565aca3a07e4693fa.tar.bz2
rails-4179141a012c84afa4756aa565aca3a07e4693fa.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/observing.rb9
-rw-r--r--activemodel/lib/active_model/secure_password.rb8
-rw-r--r--activemodel/lib/active_model/serialization.rb3
3 files changed, 11 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb
index fc84b52dd9..a6b6dfafe7 100644
--- a/activemodel/lib/active_model/observing.rb
+++ b/activemodel/lib/active_model/observing.rb
@@ -4,6 +4,7 @@ require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/remove_method'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/enumerable'
+require 'active_support/deprecation'
require 'active_support/descendants_tracker'
module ActiveModel
@@ -74,10 +75,16 @@ module ActiveModel
end
# Total number of observers.
- def count_observers
+ def observers_count
observer_instances.size
end
+ def count_observers
+ msg = "count_observers is deprecated in favor of observers_count"
+ ActiveSupport::Deprecation.warn(msg)
+ observers_count
+ end
+
protected
def instantiate_observer(observer) #:nodoc:
# string/symbol
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb
index cc0dfb1860..8711b24124 100644
--- a/activemodel/lib/active_model/secure_password.rb
+++ b/activemodel/lib/active_model/secure_password.rb
@@ -55,18 +55,14 @@ module ActiveModel
module InstanceMethodsOnActivation
# Returns self if the password is correct, otherwise false.
def authenticate(unencrypted_password)
- if BCrypt::Password.new(password_digest) == unencrypted_password
- self
- else
- false
- end
+ BCrypt::Password.new(password_digest) == unencrypted_password && self
end
# Encrypts the password into the password_digest attribute, only if the
# new password is not blank.
def password=(unencrypted_password)
- @password = unencrypted_password
unless unencrypted_password.blank?
+ @password = unencrypted_password
self.password_digest = BCrypt::Password.create(unencrypted_password)
end
end
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index 6d49e1e7ec..a5828476b1 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -84,8 +84,7 @@ module ActiveModel
hash = {}
attribute_names.each { |n| hash[n] = read_attribute_for_serialization(n) }
- method_names = Array(options[:methods]).select { |n| respond_to?(n) }
- method_names.each { |n| hash[n.to_s] = send(n) }
+ Array(options[:methods]).each { |m| hash[m.to_s] = send(m) if respond_to?(m) }
serializable_add_includes(options) do |association, records, opts|
hash[association.to_s] = if records.is_a?(Enumerable)