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

9 commits

Author SHA1 Message Date
Akira Matsuda
dd779c9686 No such class since 8d2866bb80 2019-08-02 06:21:14 +09:00
Daniel Colson
e7a28c3990
Add attribute_names to ActiveModel::Attributes
This adds `.attribute_names` and `#attribute_names` to
`ActiveModel::Attributes` along the same lines as the corresponding
methods in `ActiveRecord::AttributeMethods` (see
[`.attribute_names`][class_method] and
[`#attribute_names`][instance_method].

While I was here I also added documentation for '#attributes', which I
added in 043ce35b18. The whole class is still `#:nodoc:` so I don't
think this will have any effect for now.

[class_method]: cc834db1d0/activerecord/lib/active_record/attribute_methods.rb (L154-L160)
[instance_method]: cc834db1d0/activerecord/lib/active_record/attribute_methods.rb (L299-L301)
2019-04-22 19:48:17 -04:00
Daniel Colson
043ce35b18 Add ActiveModel::Attributes#attributes
This starts to fix #31832.
ActiveModel::Attributes includes ActiveModel::AttributeMethods,
which requires an `#attributes` method that returns a hash with string keys.
2018-02-07 18:11:14 -05:00
Sean Griffin
0af36c62a5 Allow attributes with a proc default to be marshalled
We don't implement much custom marshalling logic for these objects, but
the proc default case needs to be handled separately. Unfortunately
there's no way to just say "do what you would have done but with this
value for one ivar", so we have to manually implement `marshal_load` as
well.

The test case is a little bit funky, but I'd really like an equality
test in there, and there's no easy way to add one now that this is out
of AR (since the `attributes` method isn't here)

Fixes #31216
2018-01-23 14:12:13 -07:00
Yasuo Honda
bd4211ea13 Suppress warning: BigDecimal.new is deprecated in Active Model
`BigDecimal.new` has been deprecated in BigDecimal 1.3.3
 which will be a default for Ruby 2.5.

Refer ruby/bigdecimal@5337373

* This commit has been made as follows:

```ruby
$ cd activemodel/
$ git grep -l BigDecimal.new | grep \.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g"
```

* This commit has been tested with these Ruby versions:

```
ruby 2.5.0dev (2017-12-15 trunk 61262) [x86_64-linux]
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux]
ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux]
```
2017-12-14 19:00:00 +00:00
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
af5301089f Add simple attribute implementation backed by ivars 2009-06-17 21:27:54 -05:00