mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
- Define to_model on AR - Define to_model on ActiveModel::APICompliant - Update test fixtures to be API Compliant - Start using to_model in AP
25 lines
613 B
Ruby
25 lines
613 B
Ruby
module ActiveModel
|
|
module APICompliant
|
|
include Naming
|
|
|
|
def self.extended(klass)
|
|
klass.class_eval do
|
|
include Validations
|
|
include InstanceMethods
|
|
end
|
|
end
|
|
|
|
module InstanceMethods
|
|
def to_model
|
|
if respond_to?(:new_record?)
|
|
self.class.class_eval { def to_model() self end }
|
|
to_model
|
|
else
|
|
raise "In order to be ActiveModel API compliant, you need to define " \
|
|
"a new_record? method, which should return true if it has not " \
|
|
"yet been persisted."
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end |