From 108545a9d69215aa0205f7e6b52eb1573443d404 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 21 Jul 2009 00:56:27 -0500 Subject: Clean up validation example --- activemodel/examples/amo_ap_example.rb | 36 ---------------------------------- activemodel/examples/validations.rb | 29 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 36 deletions(-) delete mode 100644 activemodel/examples/amo_ap_example.rb create mode 100644 activemodel/examples/validations.rb (limited to 'activemodel/examples') diff --git a/activemodel/examples/amo_ap_example.rb b/activemodel/examples/amo_ap_example.rb deleted file mode 100644 index cef718d0d4..0000000000 --- a/activemodel/examples/amo_ap_example.rb +++ /dev/null @@ -1,36 +0,0 @@ -$:.push "activesupport/lib" -$:.push "activemodel/lib" - -require "active_model/validations" -require "active_model/deprecated_error_methods" -require "active_model/errors" -require "active_model/naming" - -class Person - include ActiveModel::Validations - extend ActiveModel::Naming - - validates_presence_of :name - - attr_accessor :name - def initialize(attributes = {}) - @name = attributes[:name] - end - - def persist - @persisted = true - end - - def new_record? - @persisted - end - - def to_model() self end -end - -person1 = Person.new -p person1.valid? -person1.errors - -person2 = Person.new(:name => "matz") -p person2.valid? \ No newline at end of file diff --git a/activemodel/examples/validations.rb b/activemodel/examples/validations.rb new file mode 100644 index 0000000000..3f8311ff96 --- /dev/null +++ b/activemodel/examples/validations.rb @@ -0,0 +1,29 @@ +require 'activemodel' + +class Person + include ActiveModel::Conversion + include ActiveModel::Validations + + validates_presence_of :name + + attr_accessor :name + + def initialize(attributes = {}) + @name = attributes[:name] + end + + def persist + @persisted = true + end + + def new_record? + @persisted + end +end + +person1 = Person.new +p person1.valid? +person1.errors + +person2 = Person.new(:name => "matz") +p person2.valid? -- cgit v1.2.3