diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-07-20 00:27:04 +0900 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-07-20 00:27:04 +0900 |
commit | 5ffaaa71d149c9807260c950c9a61d01fe734827 (patch) | |
tree | b014dcbe7cc8efabebca38e9e75648905e85017e /activemodel/lib | |
parent | 45d41d8012c605f21de51e7018fa31e1d07776eb (diff) | |
download | rails-5ffaaa71d149c9807260c950c9a61d01fe734827.tar.gz rails-5ffaaa71d149c9807260c950c9a61d01fe734827.tar.bz2 rails-5ffaaa71d149c9807260c950c9a61d01fe734827.zip |
Define ActiveModel API Compliance
- Define to_model on AR
- Define to_model on ActiveModel::APICompliant
- Update test fixtures to be API Compliant
- Start using to_model in AP
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model.rb | 1 | ||||
-rw-r--r-- | activemodel/lib/active_model/api_compliant.rb | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index f988cd71b8..c6f63d2fdc 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -26,6 +26,7 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) require 'active_support' module ActiveModel + autoload :APICompliant, 'active_model/api_compliant' autoload :Attributes, 'active_model/attributes' autoload :Base, 'active_model/base' autoload :DeprecatedErrorMethods, 'active_model/deprecated_error_methods' diff --git a/activemodel/lib/active_model/api_compliant.rb b/activemodel/lib/active_model/api_compliant.rb new file mode 100644 index 0000000000..26f83feb6b --- /dev/null +++ b/activemodel/lib/active_model/api_compliant.rb @@ -0,0 +1,25 @@ +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
\ No newline at end of file |