2009-09-14 15:54:43 -04:00
|
|
|
require 'active_model'
|
2009-07-19 10:24:19 -04:00
|
|
|
|
|
|
|
class Person
|
2009-07-21 01:56:27 -04:00
|
|
|
include ActiveModel::Conversion
|
2009-07-19 10:24:19 -04:00
|
|
|
include ActiveModel::Validations
|
2009-07-21 01:56:27 -04:00
|
|
|
|
2009-07-19 10:24:19 -04:00
|
|
|
validates_presence_of :name
|
2009-07-21 01:56:27 -04:00
|
|
|
|
2009-07-19 10:24:19 -04:00
|
|
|
attr_accessor :name
|
2009-07-21 01:56:27 -04:00
|
|
|
|
2009-07-19 10:24:19 -04:00
|
|
|
def initialize(attributes = {})
|
|
|
|
@name = attributes[:name]
|
|
|
|
end
|
2009-07-21 01:56:27 -04:00
|
|
|
|
2009-07-19 10:24:19 -04:00
|
|
|
def persist
|
|
|
|
@persisted = true
|
|
|
|
end
|
2009-07-21 01:56:27 -04:00
|
|
|
|
2010-02-21 05:09:21 -05:00
|
|
|
def persisted?
|
2009-07-19 10:24:19 -04:00
|
|
|
@persisted
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
person1 = Person.new
|
|
|
|
p person1.valid?
|
|
|
|
person1.errors
|
|
|
|
|
|
|
|
person2 = Person.new(:name => "matz")
|
2009-07-21 01:56:27 -04:00
|
|
|
p person2.valid?
|