diff options
| author | Willian Gustavo Veiga <beberveiga@gmail.com> | 2018-10-17 20:24:44 -0300 |
|---|---|---|
| committer | Willian Gustavo Veiga <beberveiga@gmail.com> | 2018-10-17 20:24:44 -0300 |
| commit | c8ff9bd63a2371b6f0f0b4f48abf29cf89a1d397 (patch) | |
| tree | e72e4476555fbee75961e473ce336c08fdd10fa6 /activemodel/lib/active_model/attributes.rb | |
| parent | 99bd626885b72acd44861727918ee107a649e2b4 (diff) | |
| parent | ead868315f9b0fedb351c9b451aa1f66a2dc8038 (diff) | |
| download | rails-c8ff9bd63a2371b6f0f0b4f48abf29cf89a1d397.tar.gz rails-c8ff9bd63a2371b6f0f0b4f48abf29cf89a1d397.tar.bz2 rails-c8ff9bd63a2371b6f0f0b4f48abf29cf89a1d397.zip | |
Merge branch 'master' into feature/reselect-method
Diffstat (limited to 'activemodel/lib/active_model/attributes.rb')
| -rw-r--r-- | activemodel/lib/active_model/attributes.rb | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/activemodel/lib/active_model/attributes.rb b/activemodel/lib/active_model/attributes.rb index 41fe5168f3..c3a446098c 100644 --- a/activemodel/lib/active_model/attributes.rb +++ b/activemodel/lib/active_model/attributes.rb @@ -29,17 +29,16 @@ module ActiveModel private def define_method_attribute=(name) - safe_name = name.unpack1("h*") - ActiveModel::AttributeMethods::AttrNames.set_name_cache safe_name, name - - generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1 - def __temp__#{safe_name}=(value) - name = ::ActiveModel::AttributeMethods::AttrNames::ATTR_#{safe_name} - write_attribute(name, value) - end - alias_method #{(name + '=').inspect}, :__temp__#{safe_name}= - undef_method :__temp__#{safe_name}= - STR + ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method( + generated_attribute_methods, name, writer: true, + ) do |temp_method_name, attr_name_expr| + generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{temp_method_name}(value) + name = #{attr_name_expr} + write_attribute(name, value) + end + RUBY + end end NO_DEFAULT_PROVIDED = Object.new # :nodoc: @@ -97,15 +96,4 @@ module ActiveModel write_attribute(attribute_name, value) end end - - module AttributeMethods #:nodoc: - AttrNames = Module.new { - def self.set_name_cache(name, value) - const_name = "ATTR_#{name}" - unless const_defined? const_name - const_set const_name, -value - end - end - } - end end |
