1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

5 commits

Author SHA1 Message Date
Lisa Ugray
c3675f50d2 Move Attribute and AttributeSet to ActiveModel
Use these to back the attributes API.  Stop automatically including
ActiveModel::Dirty in ActiveModel::Attributes, and make it optional.
2017-11-09 14:29:39 -05:00
Lisa Ugray
7e9ded512d Start bringing attributes API to AM
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
```
2017-10-18 13:05:30 -04:00
Joshua Peek
2685d93b07 Kill AMo ivar attributes helper 2009-07-20 23:28:58 -05:00
Joshua Peek
783db25e0c Integrate AMo JSON serializer into AR 2009-07-03 23:12:42 -05:00
Joshua Peek
af5301089f Add simple attribute implementation backed by ivars 2009-06-17 21:27:54 -05:00