aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-02-02 14:04:23 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-02-02 14:04:23 +1100
commit12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a (patch)
treea7a7b097f59eaddc8cb209a1e83505843eab99fa /activemodel
parent535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81 (diff)
parentdf8852d04d030330efcb86f16977b837473bf022 (diff)
downloadrails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.tar.gz
rails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.tar.bz2
rails-12681c2a71f6272aaa8e1fa7cc6b5df588c96b1a.zip
Merge branch 'master' of git://github.com/rails/rails
Conflicts: activemodel/README activemodel/lib/active_model/errors.rb activemodel/lib/active_model/serialization.rb railties/guides/source/3_0_release_notes.textile
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/MIT-LICENSE2
-rw-r--r--activemodel/README35
-rw-r--r--activemodel/lib/active_model.rb2
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb1
-rw-r--r--activemodel/lib/active_model/errors.rb2
-rw-r--r--activemodel/lib/active_model/lint.rb2
-rw-r--r--activemodel/lib/active_model/serialization.rb1
7 files changed, 15 insertions, 30 deletions
diff --git a/activemodel/MIT-LICENSE b/activemodel/MIT-LICENSE
index e7accc5ea1..a345a2419d 100644
--- a/activemodel/MIT-LICENSE
+++ b/activemodel/MIT-LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2004-2009 David Heinemeier Hansson
+Copyright (c) 2004-2010 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/activemodel/README b/activemodel/README
index cf103b8d6d..3945a6da06 100644
--- a/activemodel/README
+++ b/activemodel/README
@@ -1,13 +1,13 @@
= Active Model - defined interfaces for Rails
-
+
Prior to Rails 3.0, if a plugin or gem developer wanted to be able to have
an object interact with Action Pack helpers, it was required to either
copy chunks of code from Rails, or monkey patch entire helpers to make them
handle objects that did not look like Active Record. This generated code
duplication and fragile applications that broke on upgrades.
-
+
Active Model is a solution for this problem.
-
+
Active Model provides a known set of interfaces that your objects can implement
to then present a common interface to the Action Pack helpers. You can include
functionality from the following modules:
@@ -75,7 +75,7 @@ functionality from the following modules:
person.name = 'robert'
person.save
person.previous_changes # => {'name' => ['bob, 'robert']}
-
+
{Learn more}[link:classes/ActiveModel/Dirty.html]
* Adding +errors+ support to your object
@@ -84,22 +84,22 @@ functionality from the following modules:
helpers seamlessly...
class Person
-
+
def initialize
@errors = ActiveModel::Errors.new(self)
end
-
+
attr_accessor :name
attr_reader :errors
-
+
def validate!
errors.add(:name, "can not be nil") if name == nil
end
-
+
def ErrorsPerson.human_attribute_name(attr, options = {})
"Name"
end
-
+
end
... gives you...
@@ -153,19 +153,6 @@ functionality from the following modules:
s.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
{Learn more}[link:classes/ActiveModel/Serialization.html]
-
-
-* Turning your object into a finite State Machine
-
- ActiveModel::StateMachine provides a clean way to include all the methods
- you need to transform your object into a finite State Machine...
-
- light = TrafficLight.new
- light.current_state #=> :red
- light.change_color! #=> true
- light.current_state #=> :green
-
- {Learn more}[link:classes/ActiveModel/StateMachine.html]
* Integrating with Rail's internationalization (i18n) handling through
ActiveModel::Translations...
@@ -183,11 +170,13 @@ functionality from the following modules:
attr_accessor :first_name, :last_name
+
validates_each :first_name, :last_name do |record, attr, value|
record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z
end
end
+
person = Person.new(:first_name => 'zoolander')
person.valid? #=> false
@@ -214,5 +203,3 @@ functionality from the following modules:
p.valid? #=> true
{Learn more}[link:classes/ActiveModel/Validator.html]
-
- \ No newline at end of file
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb
index 1609075f7e..026430fee3 100644
--- a/activemodel/lib/active_model.rb
+++ b/activemodel/lib/active_model.rb
@@ -1,5 +1,5 @@
#--
-# Copyright (c) 2004-2009 David Heinemeier Hansson
+# Copyright (c) 2004-2010 David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 32ddf1d579..f7fb66bdfc 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -273,6 +273,7 @@ module ActiveModel
@attribute_methods_generated = nil
end
+ # Returns true if the attribute methods defined have been generated.
def generated_attribute_methods #:nodoc:
@generated_attribute_methods ||= begin
mod = Module.new
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index f1d74db5f3..d8320275df 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -62,8 +62,6 @@ module ActiveModel
# @errors = ActiveModel::Errors.new(self)
# end
# end
- #
- #
def initialize(base)
@base = base
super()
diff --git a/activemodel/lib/active_model/lint.rb b/activemodel/lib/active_model/lint.rb
index e8a39130a6..7bf0ad712d 100644
--- a/activemodel/lib/active_model/lint.rb
+++ b/activemodel/lib/active_model/lint.rb
@@ -58,7 +58,7 @@ module ActiveModel
#
# Returns an object that has :[] and :full_messages defined on it. See below
# for more details.
-
+ #
# Returns an Array of Strings that are the errors for the attribute in
# question. If localization is used, the Strings should be localized
# for the current locale. If no error is present, this method should
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index 28f95f0cdc..1c48d4613a 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -2,7 +2,6 @@ require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/slice'
module ActiveModel
-
# Provides a basic serialization to a serializable_hash for your object.
#
# A minimal implementation could be: