mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #8312 from senny/make_active_model_parts_individually_loadable
make sure that individual parts `ActiveModel` can be required by itself
This commit is contained in:
commit
3ec443086b
9 changed files with 14 additions and 21 deletions
|
@ -1,5 +1,10 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## Rails 4.0.0 (unreleased) ##
|
||||||
|
|
||||||
|
* Removed dispensable `require` statements. Make sure to require `active_model` before requiring
|
||||||
|
individual parts of the framework.
|
||||||
|
|
||||||
|
*Yves Senn*
|
||||||
|
|
||||||
* Use BCrypt's MIN_COST in the test environment for speedier tests when using `has_secure_pasword`.
|
* Use BCrypt's MIN_COST in the test environment for speedier tests when using `has_secure_pasword`.
|
||||||
|
|
||||||
*Brian Cardarella + Jeremy Kemper + Trevor Turk*
|
*Brian Cardarella + Jeremy Kemper + Trevor Turk*
|
||||||
|
|
|
@ -8,7 +8,7 @@ module ActiveModel
|
||||||
#
|
#
|
||||||
# user = User.first
|
# user = User.first
|
||||||
# user.pets.select(:id).first.user_id
|
# user.pets.select(:id).first.user_id
|
||||||
# # => ActiveModel::MissingAttributeError: missing attribute: user_id
|
# # => ActiveModel::MissingAttributeError: missing attribute: user_id
|
||||||
class MissingAttributeError < NoMethodError
|
class MissingAttributeError < NoMethodError
|
||||||
end
|
end
|
||||||
# == Active \Model Attribute Methods
|
# == Active \Model Attribute Methods
|
||||||
|
@ -202,7 +202,7 @@ module ActiveModel
|
||||||
# person.name # => "Bob"
|
# person.name # => "Bob"
|
||||||
# person.nickname # => "Bob"
|
# person.nickname # => "Bob"
|
||||||
# person.name_short? # => true
|
# person.name_short? # => true
|
||||||
# person.nickname_short? # => true
|
# person.nickname_short? # => true
|
||||||
def alias_attribute(new_name, old_name)
|
def alias_attribute(new_name, old_name)
|
||||||
self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s)
|
self.attribute_aliases = attribute_aliases.merge(new_name.to_s => old_name.to_s)
|
||||||
attribute_method_matchers.each do |matcher|
|
attribute_method_matchers.each do |matcher|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'active_support/callbacks'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
# == Active \Model \Callbacks
|
# == Active \Model \Callbacks
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'active_support/inflector'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
# == Active \Model Conversions
|
# == Active \Model Conversions
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
require 'active_model/attribute_methods'
|
|
||||||
require 'active_support/hash_with_indifferent_access'
|
require 'active_support/hash_with_indifferent_access'
|
||||||
require 'active_support/core_ext/object/duplicable'
|
require 'active_support/core_ext/object/duplicable'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
require 'active_support/inflector'
|
|
||||||
require 'active_support/core_ext/hash/except'
|
require 'active_support/core_ext/hash/except'
|
||||||
require 'active_support/core_ext/module/introspection'
|
require 'active_support/core_ext/module/introspection'
|
||||||
|
|
||||||
|
@ -56,8 +55,8 @@ module ActiveModel
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# BlogPost.model_name <=> 'BlogPost' # => 0
|
# BlogPost.model_name <=> 'BlogPost' # => 0
|
||||||
# BlogPost.model_name <=> 'Blog' # => 1
|
# BlogPost.model_name <=> 'Blog' # => 1
|
||||||
# BlogPost.model_name <=> 'BlogPosts' # => -1
|
# BlogPost.model_name <=> 'BlogPosts' # => -1
|
||||||
|
|
||||||
##
|
##
|
||||||
# :method: =~
|
# :method: =~
|
||||||
|
|
|
@ -5,7 +5,6 @@ require 'active_support/core_ext/module/remove_method'
|
||||||
require 'active_support/core_ext/string/inflections'
|
require 'active_support/core_ext/string/inflections'
|
||||||
require 'active_support/core_ext/enumerable'
|
require 'active_support/core_ext/enumerable'
|
||||||
require 'active_support/core_ext/object/try'
|
require 'active_support/core_ext/object/try'
|
||||||
require 'active_support/descendants_tracker'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
# == Active \Model Observers Activation
|
# == Active \Model Observers Activation
|
||||||
|
@ -49,7 +48,7 @@ module ActiveModel
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# ORM.observers = :cacher, :garbage_collector
|
# ORM.observers = :cacher, :garbage_collector
|
||||||
# ORM.observers # => [:cacher, :garbage_collector]
|
# ORM.observers # => [:cacher, :garbage_collector]
|
||||||
# ORM.observers.class # => ActiveModel::ObserverArray
|
# ORM.observers.class # => ActiveModel::ObserverArray
|
||||||
def observers
|
def observers
|
||||||
@observers ||= ObserverArray.new(self)
|
@observers ||= ObserverArray.new(self)
|
||||||
|
@ -328,8 +327,8 @@ module ActiveModel
|
||||||
# Returns the class observed by default. It's inferred from the observer's
|
# Returns the class observed by default. It's inferred from the observer's
|
||||||
# class name.
|
# class name.
|
||||||
#
|
#
|
||||||
# PersonObserver.observed_class # => Person
|
# PersonObserver.observed_class # => Person
|
||||||
# AccountObserver.observed_class # => Account
|
# AccountObserver.observed_class # => Account
|
||||||
def observed_class
|
def observed_class
|
||||||
name[/(.*)Observer/, 1].try :constantize
|
name[/(.*)Observer/, 1].try :constantize
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
require 'active_support/core_ext/array/extract_options'
|
require 'active_support/core_ext/array/extract_options'
|
||||||
require 'active_support/core_ext/hash/keys'
|
require 'active_support/core_ext/hash/keys'
|
||||||
require 'active_support/core_ext/hash/except'
|
require 'active_support/core_ext/hash/except'
|
||||||
require 'active_model/errors'
|
|
||||||
require 'active_model/validations/callbacks'
|
|
||||||
require 'active_model/validator'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'active_support/callbacks'
|
|
||||||
|
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
module Validations
|
module Validations
|
||||||
# == Active \Model Validation Callbacks
|
# == Active \Model Validation Callbacks
|
||||||
|
@ -85,8 +83,8 @@ module ActiveModel
|
||||||
# person = Person.new
|
# person = Person.new
|
||||||
# person.name = ''
|
# person.name = ''
|
||||||
# person.valid? # => false
|
# person.valid? # => false
|
||||||
# person.status # => false
|
# person.status # => false
|
||||||
# person.name = 'bob'
|
# person.name = 'bob'
|
||||||
# person.valid? # => true
|
# person.valid? # => true
|
||||||
# person.status # => true
|
# person.status # => true
|
||||||
def after_validation(*args, &block)
|
def after_validation(*args, &block)
|
||||||
|
|
Loading…
Reference in a new issue