| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
| |
When requesting columns names from database adapters AR:Result
would dup/freeze column names, this prefers using fstrings which
cuts down on repeat allocations
Attributes that are retained keep these fstrings around for the long
term
Note, this has the highest impact on "short" result sets, eg: Topic.first where you can void allocating the number of columns * String.
|
|
|
|
|
| |
https://bugs.ruby-lang.org/issues/12752
https://ruby-doc.org/core-2.4.0/String.html#method-i-unpack1
|
|
|
|
|
|
| |
This starts to fix #31832.
ActiveModel::Attributes includes ActiveModel::AttributeMethods,
which requires an `#attributes` method that returns a hash with string keys.
|
|
|
|
|
|
|
|
| |
`define_attribute_methods` splats the arguments,
then calls out to `define_attribute_method` for
each. When defining a singule attribute, using
the singular version of the method saves us an
array and an extra method call.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Attribute modules (`Attribute`, `Attributes`, `AttributeSet`) uses
`Type`, but referencing `Type` before the modules still fail.
```
% ./bin/test -w test/cases/attribute_test.rb -n test_with_value_from_user_validates_the_value
Run options: -n test_with_value_from_user_validates_the_value --seed 31876
E
Error:
ActiveModel::AttributeTest#test_with_value_from_user_validates_the_value:
NameError: uninitialized constant ActiveModel::AttributeTest::Type
/Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attribute_test.rb:233:in `block in <class:AttributeTest>'
bin/test test/cases/attribute_test.rb:232
Finished in 0.002985s, 335.0479 runs/s, 335.0479 assertions/s.
1 runs, 1 assertions, 0 failures, 1 errors, 0 skips
```
Probably we need more autoloading at least `Type`.
|
| |
|
|
|
|
|
| |
Use these to back the attributes API. Stop automatically including
ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This is the first PR of a WIP to bring the attributes API to
ActiveModel. It is not yet ready for public API.
The `attributes_dirty_test.rb` file was created based on `dirty_test.rb`,
and the simplifications in the diff do much to motivate this change.
```
diff activemodel/test/cases/dirty_test.rb activemodel/test/cases/attributes_dirty_test.rb
3a4
> require "active_model/attributes"
5c6
< class DirtyTest < ActiveModel::TestCase
---
> class AttributesDirtyTest < ActiveModel::TestCase
7,41c8,12
< include ActiveModel::Dirty
< define_attribute_methods :name, :color, :size
<
< def initialize
< @name = nil
< @color = nil
< @size = nil
< end
<
< def name
< @name
< end
<
< def name=(val)
< name_will_change!
< @name = val
< end
<
< def color
< @color
< end
<
< def color=(val)
< color_will_change! unless val == @color
< @color = val
< end
<
< def size
< @size
< end
<
< def size=(val)
< attribute_will_change!(:size) unless val == @size
< @size = val
< end
---
> include ActiveModel::Model
> include ActiveModel::Attributes
> attribute :name, :string
> attribute :color, :string
> attribute :size, :integer
```
|
| |
|
| |
|
|
|