diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-05-29 18:01:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 18:01:50 +0200 |
commit | 1c275d812f35f53f93cd96184a4f319983766cc5 (patch) | |
tree | b063afeb12dd369f358ad18517e5e8915455df0e /activemodel/lib | |
parent | edc90c858d4cbf1a8e4bfb7347b34348bb30e92c (diff) | |
download | rails-1c275d812f35f53f93cd96184a4f319983766cc5.tar.gz rails-1c275d812f35f53f93cd96184a4f319983766cc5.tar.bz2 rails-1c275d812f35f53f93cd96184a4f319983766cc5.zip |
Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute
* Convert to using class_attribute default rather than explicit setter
* Removed instance_accessor option by mistake
* False is a valid default value
* Documentation
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 5 | ||||
-rw-r--r-- | activemodel/lib/active_model/serializers/json.rb | 3 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 3 |
3 files changed, 4 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index b5c0b43b61..b3b39bf7ae 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -68,9 +68,8 @@ module ActiveModel CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/ included do - class_attribute :attribute_aliases, :attribute_method_matchers, instance_writer: false - self.attribute_aliases = {} - self.attribute_method_matchers = [ClassMethods::AttributeMethodMatcher.new] + class_attribute :attribute_aliases, instance_writer: false, default: {} + class_attribute :attribute_method_matchers, instance_writer: false, default: [ ClassMethods::AttributeMethodMatcher.new ] end module ClassMethods diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index a9d92eb92a..205b84ddb4 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -10,8 +10,7 @@ module ActiveModel included do extend ActiveModel::Naming - class_attribute :include_root_in_json, instance_writer: false - self.include_root_in_json = false + class_attribute :include_root_in_json, instance_writer: false, default: false end # Returns a hash representing the model. Some configuration can be diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 1f14a068d1..ae1d69f685 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -49,8 +49,7 @@ module ActiveModel private :validation_context= define_callbacks :validate, scope: :name - class_attribute :_validators, instance_writer: false - self._validators = Hash.new { |h, k| h[k] = [] } + class_attribute :_validators, instance_writer: false, default: Hash.new { |h, k| h[k] = [] } end module ClassMethods |