diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-20 16:57:23 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-20 16:57:23 -0300 |
commit | 9a28bd787660b08aae36155066e61d3608d0b4dd (patch) | |
tree | 2d10dd32ad28cc070c3d142c45d6a35fcd5ae43e /activemodel/lib/active_model/api_compliant.rb | |
parent | b326faef0936e5a845d1f6eb9ed2200babfd05f8 (diff) | |
parent | 37658f15bb88e054635a496327a4a82bb50fd5d5 (diff) | |
download | rails-9a28bd787660b08aae36155066e61d3608d0b4dd.tar.gz rails-9a28bd787660b08aae36155066e61d3608d0b4dd.tar.bz2 rails-9a28bd787660b08aae36155066e61d3608d0b4dd.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activemodel/lib/active_model/api_compliant.rb')
-rw-r--r-- | activemodel/lib/active_model/api_compliant.rb | 25 |
1 files changed, 25 insertions, 0 deletions
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 |