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.
@@ -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
- if name =~ /^[a-zA-Z_]\w*[!?=]?$/
105
- sing.class_eval <<-eorb, __FILE__, __LINE__ + 1
106
- def #{name}; #{value.nil? ? 'nil' : value.to_s.inspect}; end
107
- eorb
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
- module_eval <<-STR, __FILE__, __LINE__ + 1
231
- def #{matcher.method_name(new_name)}(*args)
232
- send(:'#{matcher.method_name(old_name)}', *args)
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
- STR
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 <<-STR, __FILE__, __LINE__ + 1
275
- if method_defined?(:'#{method_name}')
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
- define_method('#{method_name}') do |*args|
279
- send(:'#{matcher.method_missing_target}', '#{attr_name}', *args)
280
- end
281
- STR
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
@@ -2,8 +2,8 @@ module ActiveModel
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
6
- PRE = nil
5
+ TINY = 8
6
+ PRE = "rc1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
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: 9
5
- prerelease:
4
+ hash: 15424055
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 3.0.7
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-04-18 00:00:00 Z
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: 9
30
+ hash: 15424055
29
31
  segments:
30
32
  - 3
31
33
  - 0
32
- - 7
33
- version: 3.0.7
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: 3
142
+ hash: 25
139
143
  segments:
140
- - 0
141
- version: "0"
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.7.2
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).