activemodel 3.0.7 → 3.0.8.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_model/attribute_methods.rb +39 -14
- data/lib/active_model/version.rb +2 -2
- metadata +19 -13
@@ -56,6 +56,8 @@ module ActiveModel
|
|
56
56
|
module AttributeMethods
|
57
57
|
extend ActiveSupport::Concern
|
58
58
|
|
59
|
+
COMPILABLE_REGEXP = /^[a-zA-Z_]\w*[!?=]?$/
|
60
|
+
|
59
61
|
module ClassMethods
|
60
62
|
# Defines an "attribute" method (like +inheritance_column+ or +table_name+).
|
61
63
|
# A new (class) method will be created with the given name. If a value is
|
@@ -101,10 +103,13 @@ module ActiveModel
|
|
101
103
|
if block_given?
|
102
104
|
sing.send :define_method, name, &block
|
103
105
|
else
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
# If we can compile the method name, do it. Otherwise use define_method.
|
107
|
+
# This is an important *optimization*, please don't change it. define_method
|
108
|
+
# has slower dispatch and consumes more memory.
|
109
|
+
if name =~ COMPILABLE_REGEXP
|
110
|
+
sing.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
111
|
+
def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end
|
112
|
+
RUBY
|
108
113
|
else
|
109
114
|
value = value.to_s if value
|
110
115
|
sing.send(:define_method, name) { value }
|
@@ -227,11 +232,20 @@ module ActiveModel
|
|
227
232
|
|
228
233
|
def alias_attribute(new_name, old_name)
|
229
234
|
attribute_method_matchers.each do |matcher|
|
230
|
-
|
231
|
-
|
232
|
-
|
235
|
+
matcher_new = matcher.method_name(new_name).to_s
|
236
|
+
matcher_old = matcher.method_name(old_name).to_s
|
237
|
+
|
238
|
+
if matcher_new =~ COMPILABLE_REGEXP && matcher_old =~ COMPILABLE_REGEXP
|
239
|
+
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
240
|
+
def #{matcher_new}(*args)
|
241
|
+
send(:#{matcher_old}, *args)
|
242
|
+
end
|
243
|
+
RUBY
|
244
|
+
else
|
245
|
+
define_method(matcher_new) do |*args|
|
246
|
+
send(matcher_old, *args)
|
233
247
|
end
|
234
|
-
|
248
|
+
end
|
235
249
|
end
|
236
250
|
end
|
237
251
|
|
@@ -271,14 +285,25 @@ module ActiveModel
|
|
271
285
|
else
|
272
286
|
method_name = matcher.method_name(attr_name)
|
273
287
|
|
274
|
-
generated_attribute_methods.module_eval <<-
|
275
|
-
if method_defined?(
|
288
|
+
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
289
|
+
if method_defined?('#{method_name}')
|
276
290
|
undef :'#{method_name}'
|
277
291
|
end
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
292
|
+
RUBY
|
293
|
+
|
294
|
+
if method_name.to_s =~ COMPILABLE_REGEXP
|
295
|
+
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
296
|
+
def #{method_name}(*args)
|
297
|
+
send(:#{matcher.method_missing_target}, '#{attr_name}', *args)
|
298
|
+
end
|
299
|
+
RUBY
|
300
|
+
else
|
301
|
+
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
302
|
+
define_method('#{method_name}') do |*args|
|
303
|
+
send('#{matcher.method_missing_target}', '#{attr_name}', *args)
|
304
|
+
end
|
305
|
+
RUBY
|
306
|
+
end
|
282
307
|
end
|
283
308
|
end
|
284
309
|
end
|
data/lib/active_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15424055
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
9
|
+
- 8
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 3.0.8.rc1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- David Heinemeier Hansson
|
@@ -15,7 +17,7 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2011-
|
20
|
+
date: 2011-05-25 00:00:00 Z
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
23
|
name: activesupport
|
@@ -25,12 +27,14 @@ dependencies:
|
|
25
27
|
requirements:
|
26
28
|
- - "="
|
27
29
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
30
|
+
hash: 15424055
|
29
31
|
segments:
|
30
32
|
- 3
|
31
33
|
- 0
|
32
|
-
-
|
33
|
-
|
34
|
+
- 8
|
35
|
+
- rc
|
36
|
+
- 1
|
37
|
+
version: 3.0.8.rc1
|
34
38
|
type: :runtime
|
35
39
|
version_requirements: *id001
|
36
40
|
- !ruby/object:Gem::Dependency
|
@@ -133,16 +137,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
138
|
none: false
|
135
139
|
requirements:
|
136
|
-
- - "
|
140
|
+
- - ">"
|
137
141
|
- !ruby/object:Gem::Version
|
138
|
-
hash:
|
142
|
+
hash: 25
|
139
143
|
segments:
|
140
|
-
-
|
141
|
-
|
144
|
+
- 1
|
145
|
+
- 3
|
146
|
+
- 1
|
147
|
+
version: 1.3.1
|
142
148
|
requirements: []
|
143
149
|
|
144
150
|
rubyforge_project: activemodel
|
145
|
-
rubygems_version: 1.
|
151
|
+
rubygems_version: 1.8.2
|
146
152
|
signing_key:
|
147
153
|
specification_version: 3
|
148
154
|
summary: A toolkit for building modeling frameworks (part of Rails).
|