@@ -20,6 +20,10 @@ def cast_with_active_record(object, type)
20
20
21
21
if object . is_a? ( ::ActiveRecord ::Base )
22
22
cast = :active_record_instance
23
+ elsif object . is_a? ( Class ) && object . include? ( ::ActiveModel ::Attributes )
24
+ cast = :active_model_class
25
+ elsif object . is_a? ( ::ActiveModel ::Attributes )
26
+ cast = :active_model_instance
23
27
elsif object . is_a? ( ::ActiveModel ::Errors )
24
28
cast = :active_model_error
25
29
elsif object . is_a? ( Class ) && object . ancestors . include? ( ::ActiveRecord ::Base )
@@ -71,6 +75,32 @@ def awesome_active_record_class(object)
71
75
[ awesome_simple ( "class #{ object } < #{ object . superclass } " , :class ) , awesome_hash ( data ) ] . join ( ' ' )
72
76
end
73
77
78
+ # Format ActiveModel instance object.
79
+ #------------------------------------------------------------------------------
80
+ def awesome_active_model_instance ( object )
81
+ return object . inspect unless defined? ( ::ActiveSupport ::OrderedHash )
82
+ return awesome_object ( object ) if @options [ :raw ]
83
+
84
+ data = object . attributes . each_with_object ( ::ActiveSupport ::OrderedHash . new ) do |c , hash |
85
+ hash [ c . first . to_sym ] = c . last
86
+ end
87
+
88
+ [ awesome_simple ( object . to_s , :active_model_instance ) , awesome_hash ( data ) ] . join ( ' ' )
89
+ end
90
+
91
+ # Format ActiveModel class object.
92
+ #------------------------------------------------------------------------------
93
+ def awesome_active_model_class ( object )
94
+ return object . inspect unless defined? ( ::ActiveSupport ::OrderedHash )
95
+ return awesome_class ( object ) if @options [ :raw ]
96
+
97
+ data = object . attribute_types . each_with_object ( ::ActiveSupport ::OrderedHash . new ) do |c , hash |
98
+ hash [ c . first . to_sym ] = c . last . type
99
+ end
100
+
101
+ [ awesome_simple ( "class #{ object } < #{ object . superclass } " , :class ) , awesome_hash ( data ) ] . join ( ' ' )
102
+ end
103
+
74
104
# Format ActiveModel error object.
75
105
#------------------------------------------------------------------------------
76
106
def awesome_active_model_error ( object )
0 commit comments