Skip to content

Commit c6e1272

Browse files
authored
Revert "Port BeforeTypeCast to Active Model"
1 parent 27c28ce commit c6e1272

File tree

8 files changed

+105
-240
lines changed

8 files changed

+105
-240
lines changed

activemodel/CHANGELOG.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
* Port the `BeforeTypeCast` module to Active Model. Classes that include
2-
`ActiveModel::Attributes` will now automatically define methods such as
3-
`*_before_type_cast`, `*_for_database`, etc. These methods behave the same
4-
for Active Model as they do for Active Record.
5-
6-
```ruby
7-
class MyModel
8-
include ActiveModel::Attributes
9-
10-
attribute :my_attribute, :integer
11-
end
12-
13-
m = MyModel.new
14-
m.my_attribute = "123"
15-
m.my_attribute # => 123
16-
m.my_attribute_before_type_cast # => "123"
17-
m.read_attribute_before_type_cast(:my_attribute) # => "123"
18-
```
19-
20-
*Jonathan Hefner*
21-
221
* Port the `type_for_attribute` method to Active Model. Classes that include
232
`ActiveModel::Attributes` will now provide this method. This method behaves
243
the same for Active Model as it does for Active Record.

activemodel/lib/active_model.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module ActiveModel
3939
autoload :AttributeAssignment
4040
autoload :AttributeMethods
4141
autoload :AttributeRegistration
42-
autoload :BeforeTypeCast
4342
autoload :BlockValidator, "active_model/validator"
4443
autoload :Callbacks
4544
autoload :Conversion

activemodel/lib/active_model/attribute_methods.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,6 @@ def aliases_by_attribute_name # :nodoc:
376376
@aliases_by_attribute_name ||= Hash.new { |h, k| h[k] = [] }
377377
end
378378

379-
def resolve_attribute_name(name) # :nodoc:
380-
attribute_aliases.fetch(super, &:itself)
381-
end
382-
383379
private
384380
def inherited(base) # :nodoc:
385381
super
@@ -388,6 +384,10 @@ def inherited(base) # :nodoc:
388384
end
389385
end
390386

387+
def resolve_attribute_name(name)
388+
attribute_aliases.fetch(super, &:itself)
389+
end
390+
391391
def generated_attribute_methods
392392
@generated_attribute_methods ||= Module.new.tap { |mod| include mod }
393393
end

activemodel/lib/active_model/attribute_registration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def type_for_attribute(attribute_name, &block)
5555
end
5656
end
5757

58-
def resolve_attribute_name(name) # :nodoc:
59-
name.to_s
60-
end
61-
6258
private
6359
PendingType = Struct.new(:name, :type) do # :nodoc:
6460
def apply_to(attribute_set)
@@ -107,6 +103,10 @@ def reset_default_attributes!
107103
@attribute_types = nil
108104
end
109105

106+
def resolve_attribute_name(name)
107+
name.to_s
108+
end
109+
110110
def resolve_type_name(name, **options)
111111
Type.lookup(name, **options)
112112
end

activemodel/lib/active_model/attributes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module Attributes
3131
extend ActiveSupport::Concern
3232
include ActiveModel::AttributeRegistration
3333
include ActiveModel::AttributeMethods
34-
include ActiveModel::BeforeTypeCast
3534

3635
included do
3736
attribute_method_suffix "=", parameters: "value"

activemodel/lib/active_model/before_type_cast.rb

Lines changed: 0 additions & 128 deletions
This file was deleted.

activemodel/test/cases/before_type_cast_test.rb

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)