activemodel 3.0.0.beta2 → 3.0.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/lib/active_model/attribute_methods.rb +2 -2
- data/lib/active_model/callbacks.rb +3 -3
- data/lib/active_model/dirty.rb +12 -12
- data/lib/active_model/errors.rb +7 -0
- data/lib/active_model/version.rb +1 -1
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -221,7 +221,7 @@ module ActiveModel
|
|
221
221
|
|
222
222
|
def alias_attribute(new_name, old_name)
|
223
223
|
attribute_method_matchers.each do |matcher|
|
224
|
-
module_eval <<-STR, __FILE__, __LINE__+1
|
224
|
+
module_eval <<-STR, __FILE__, __LINE__ + 1
|
225
225
|
def #{matcher.method_name(new_name)}(*args)
|
226
226
|
send(:#{matcher.method_name(old_name)}, *args)
|
227
227
|
end
|
@@ -265,7 +265,7 @@ module ActiveModel
|
|
265
265
|
else
|
266
266
|
method_name = matcher.method_name(attr_name)
|
267
267
|
|
268
|
-
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__+1
|
268
|
+
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
|
269
269
|
if method_defined?(:#{method_name})
|
270
270
|
undef :#{method_name}
|
271
271
|
end
|
@@ -105,7 +105,7 @@ module ActiveModel
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def _define_before_model_callback(klass, callback) #:nodoc:
|
108
|
-
klass.class_eval <<-CALLBACK, __FILE__, __LINE__
|
108
|
+
klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
|
109
109
|
def self.before_#{callback}(*args, &block)
|
110
110
|
set_callback(:#{callback}, :before, *args, &block)
|
111
111
|
end
|
@@ -113,7 +113,7 @@ module ActiveModel
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def _define_around_model_callback(klass, callback) #:nodoc:
|
116
|
-
klass.class_eval <<-CALLBACK, __FILE__, __LINE__
|
116
|
+
klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
|
117
117
|
def self.around_#{callback}(*args, &block)
|
118
118
|
set_callback(:#{callback}, :around, *args, &block)
|
119
119
|
end
|
@@ -121,7 +121,7 @@ module ActiveModel
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def _define_after_model_callback(klass, callback) #:nodoc:
|
124
|
-
klass.class_eval <<-CALLBACK, __FILE__, __LINE__
|
124
|
+
klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
|
125
125
|
def self.after_#{callback}(*args, &block)
|
126
126
|
options = args.extract_options!
|
127
127
|
options[:prepend] = true
|
data/lib/active_model/dirty.rb
CHANGED
@@ -91,17 +91,12 @@ module ActiveModel
|
|
91
91
|
attribute_method_affix :prefix => 'reset_', :suffix => '!'
|
92
92
|
end
|
93
93
|
|
94
|
-
def initialize(*)
|
95
|
-
@changed_attributes = {}
|
96
|
-
super
|
97
|
-
end
|
98
|
-
|
99
94
|
# Do any attributes have unsaved changes?
|
100
95
|
# person.changed? # => false
|
101
96
|
# person.name = 'bob'
|
102
97
|
# person.changed? # => true
|
103
98
|
def changed?
|
104
|
-
|
99
|
+
!changed_attributes.empty?
|
105
100
|
end
|
106
101
|
|
107
102
|
# List of attributes with unsaved changes.
|
@@ -109,7 +104,7 @@ module ActiveModel
|
|
109
104
|
# person.name = 'bob'
|
110
105
|
# person.changed # => ['name']
|
111
106
|
def changed
|
112
|
-
|
107
|
+
changed_attributes.keys
|
113
108
|
end
|
114
109
|
|
115
110
|
# Map of changed attrs => [original value, new value].
|
@@ -130,19 +125,24 @@ module ActiveModel
|
|
130
125
|
end
|
131
126
|
|
132
127
|
private
|
128
|
+
# Map of change <tt>attr => original value</tt>.
|
129
|
+
def changed_attributes
|
130
|
+
@changed_attributes ||= {}
|
131
|
+
end
|
132
|
+
|
133
133
|
# Handle <tt>*_changed?</tt> for +method_missing+.
|
134
134
|
def attribute_changed?(attr)
|
135
|
-
|
135
|
+
changed_attributes.include?(attr)
|
136
136
|
end
|
137
137
|
|
138
138
|
# Handle <tt>*_change</tt> for +method_missing+.
|
139
139
|
def attribute_change(attr)
|
140
|
-
[
|
140
|
+
[changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
|
141
141
|
end
|
142
142
|
|
143
143
|
# Handle <tt>*_was</tt> for +method_missing+.
|
144
144
|
def attribute_was(attr)
|
145
|
-
attribute_changed?(attr) ?
|
145
|
+
attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
|
146
146
|
end
|
147
147
|
|
148
148
|
# Handle <tt>*_will_change!</tt> for +method_missing+.
|
@@ -153,12 +153,12 @@ module ActiveModel
|
|
153
153
|
rescue TypeError, NoMethodError
|
154
154
|
end
|
155
155
|
|
156
|
-
|
156
|
+
changed_attributes[attr] = value
|
157
157
|
end
|
158
158
|
|
159
159
|
# Handle <tt>reset_*!</tt> for +method_missing+.
|
160
160
|
def reset_attribute!(attr)
|
161
|
-
__send__("#{attr}=",
|
161
|
+
__send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
data/lib/active_model/errors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
1
3
|
require 'active_support/core_ext/array/wrap'
|
2
4
|
require 'active_support/core_ext/string/inflections'
|
3
5
|
require 'active_support/core_ext/object/blank'
|
@@ -140,6 +142,11 @@ module ActiveModel
|
|
140
142
|
to_a.size
|
141
143
|
end
|
142
144
|
|
145
|
+
# Returns true if there are any errors, false if not.
|
146
|
+
def empty?
|
147
|
+
all? { |k, v| v && v.empty? }
|
148
|
+
end
|
149
|
+
|
143
150
|
# Returns an xml formatted representation of the Errors hash.
|
144
151
|
#
|
145
152
|
# p.errors.add(:name, "can't be blank")
|
data/lib/active_model/version.rb
CHANGED
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 3
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.0.
|
9
|
+
- beta3
|
10
|
+
version: 3.0.0.beta3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Heinemeier Hansson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-04-
|
18
|
+
date: 2010-04-13 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
- 3
|
30
30
|
- 0
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
version: 3.0.0.
|
32
|
+
- beta3
|
33
|
+
version: 3.0.0.beta3
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
description: A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.
|