activemodel 3.1.3 → 3.1.4.rc1

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.
@@ -287,7 +287,7 @@ module ActiveModel
287
287
  unless instance_method_already_implemented?(matcher.method_name(attr_name))
288
288
  generate_method = "define_method_#{matcher.prefix}attribute#{matcher.suffix}"
289
289
 
290
- if respond_to?(generate_method)
290
+ if respond_to?(generate_method, true)
291
291
  send(generate_method, attr_name)
292
292
  else
293
293
  method_name = matcher.method_name(attr_name)
@@ -41,7 +41,7 @@ module ActiveModel
41
41
  # You can choose not to have all three callbacks by passing a hash to the
42
42
  # define_model_callbacks method.
43
43
  #
44
- # define_model_callbacks :create, :only => :after, :before
44
+ # define_model_callbacks :create, :only => [:after, :before]
45
45
  #
46
46
  # Would only create the after_create and before_create callback methods in your
47
47
  # class.
@@ -79,6 +79,19 @@ module ActiveModel
79
79
  @messages = ActiveSupport::OrderedHash.new
80
80
  end
81
81
 
82
+ def initialize_dup(other)
83
+ @messages = other.messages.dup
84
+ end
85
+
86
+ # Backport dup from 1.9 so that #initialize_dup gets called
87
+ unless Object.respond_to?(:initialize_dup)
88
+ def dup # :nodoc:
89
+ copy = super
90
+ copy.initialize_dup(self)
91
+ copy
92
+ end
93
+ end
94
+
82
95
  # Clear the messages
83
96
  def clear
84
97
  messages.clear
@@ -99,6 +112,11 @@ module ActiveModel
99
112
  messages[key] = value
100
113
  end
101
114
 
115
+ # Delete messages for +key+
116
+ def delete(key)
117
+ messages.delete(key)
118
+ end
119
+
102
120
  # When passed a symbol or a name of a method, returns an array of errors
103
121
  # for the method.
104
122
  #
@@ -113,7 +131,7 @@ module ActiveModel
113
131
  # p.errors[:name] = "must be set"
114
132
  # p.errors[:name] # => ['must be set']
115
133
  def []=(attribute, error)
116
- self[attribute.to_sym] << error
134
+ self[attribute] << error
117
135
  end
118
136
 
119
137
  # Iterates through each error key, value pair in the error messages hash.
@@ -4,7 +4,9 @@ require 'active_support/core_ext/module/introspection'
4
4
 
5
5
  module ActiveModel
6
6
  class Name < String
7
- attr_reader :singular, :plural, :element, :collection, :partial_path, :route_key, :param_key, :i18n_key
7
+ attr_reader :singular, :plural, :element, :collection, :partial_path,
8
+ :singular_route_key, :route_key, :param_key, :i18n_key
9
+
8
10
  alias_method :cache_key, :collection
9
11
 
10
12
  def initialize(klass, namespace = nil, name = nil)
@@ -19,9 +21,13 @@ module ActiveModel
19
21
  @human = ActiveSupport::Inflector.humanize(@element).freeze
20
22
  @collection = ActiveSupport::Inflector.tableize(self).freeze
21
23
  @partial_path = "#{@collection}/#{@element}".freeze
22
- @param_key = (namespace ? _singularize(@unnamespaced) : @singular).freeze
23
- @route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural).freeze
24
- @i18n_key = self.underscore.to_sym
24
+ @param_key = (namespace ? _singularize(@unnamespaced) : @singular).freeze
25
+ @i18n_key = self.underscore.to_sym
26
+
27
+ @route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
28
+ @singular_route_key = ActiveSupport::Inflector.singularize(@route_key).freeze
29
+ @route_key << "_index" if @plural == @singular
30
+ @route_key.freeze
25
31
  end
26
32
 
27
33
  # Transform the model name into a more humane format, using I18n. By default,
@@ -105,6 +111,18 @@ module ActiveModel
105
111
  plural(record_or_class) == singular(record_or_class)
106
112
  end
107
113
 
114
+ # Returns string to use while generating route names. It differs for
115
+ # namespaced models regarding whether it's inside isolated engine.
116
+ #
117
+ # For isolated engine:
118
+ # ActiveModel::Naming.route_key(Blog::Post) #=> post
119
+ #
120
+ # For shared engine:
121
+ # ActiveModel::Naming.route_key(Blog::Post) #=> blog_post
122
+ def self.singular_route_key(record_or_class)
123
+ model_name_from_record_or_class(record_or_class).singular_route_key
124
+ end
125
+
108
126
  # Returns string to use while generating route names. It differs for
109
127
  # namespaced models regarding whether it's inside isolated engine.
110
128
  #
@@ -113,6 +131,9 @@ module ActiveModel
113
131
  #
114
132
  # For shared engine:
115
133
  # ActiveModel::Naming.route_key(Blog::Post) #=> blog_posts
134
+ #
135
+ # The route key also considers if the noun is uncountable and, in
136
+ # such cases, automatically appends _index.
116
137
  def self.route_key(record_or_class)
117
138
  model_name_from_record_or_class(record_or_class).route_key
118
139
  end
@@ -2,8 +2,8 @@ module ActiveModel
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- TINY = 3
6
- PRE = nil
5
+ TINY = 4
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: 5
5
- prerelease:
4
+ hash: 15424071
5
+ prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 3
10
- version: 3.1.3
9
+ - 4
10
+ - rc
11
+ - 1
12
+ version: 3.1.4.rc1
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,29 +17,30 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-11-20 00:00:00 Z
20
+ date: 2012-02-22 00:00:00 Z
19
21
  dependencies:
20
22
  - !ruby/object:Gem::Dependency
21
23
  name: activesupport
22
- type: :runtime
23
24
  prerelease: false
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirement: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - "="
28
29
  - !ruby/object:Gem::Version
29
- hash: 5
30
+ hash: 15424071
30
31
  segments:
31
32
  - 3
32
33
  - 1
33
- - 3
34
- version: 3.1.3
35
- requirement: *id001
34
+ - 4
35
+ - rc
36
+ - 1
37
+ version: 3.1.4.rc1
38
+ type: :runtime
39
+ version_requirements: *id001
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: builder
38
- type: :runtime
39
42
  prerelease: false
40
- version_requirements: &id002 !ruby/object:Gem::Requirement
43
+ requirement: &id002 !ruby/object:Gem::Requirement
41
44
  none: false
42
45
  requirements:
43
46
  - - ~>
@@ -48,12 +51,12 @@ dependencies:
48
51
  - 0
49
52
  - 0
50
53
  version: 3.0.0
51
- requirement: *id002
54
+ type: :runtime
55
+ version_requirements: *id002
52
56
  - !ruby/object:Gem::Dependency
53
57
  name: i18n
54
- type: :runtime
55
58
  prerelease: false
56
- version_requirements: &id003 !ruby/object:Gem::Requirement
59
+ requirement: &id003 !ruby/object:Gem::Requirement
57
60
  none: false
58
61
  requirements:
59
62
  - - ~>
@@ -63,7 +66,8 @@ dependencies:
63
66
  - 0
64
67
  - 6
65
68
  version: "0.6"
66
- requirement: *id003
69
+ type: :runtime
70
+ version_requirements: *id003
67
71
  description: A toolkit for building modeling frameworks like Active Record and Active Resource. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.
68
72
  email: david@loudthinking.com
69
73
  executables: []
@@ -76,41 +80,41 @@ files:
76
80
  - CHANGELOG.md
77
81
  - MIT-LICENSE
78
82
  - README.rdoc
79
- - lib/active_model.rb
80
- - lib/active_model/mass_assignment_security.rb
81
- - lib/active_model/locale/en.yml
82
- - lib/active_model/conversion.rb
83
83
  - lib/active_model/attribute_methods.rb
84
+ - lib/active_model/callbacks.rb
85
+ - lib/active_model/conversion.rb
84
86
  - lib/active_model/dirty.rb
85
- - lib/active_model/mass_assignment_security/sanitizer.rb
86
- - lib/active_model/mass_assignment_security/permission_set.rb
87
87
  - lib/active_model/errors.rb
88
- - lib/active_model/test_case.rb
89
- - lib/active_model/observer_array.rb
90
88
  - lib/active_model/lint.rb
91
- - lib/active_model/observing.rb
92
- - lib/active_model/version.rb
93
- - lib/active_model/serialization.rb
89
+ - lib/active_model/locale/en.yml
90
+ - lib/active_model/mass_assignment_security/permission_set.rb
91
+ - lib/active_model/mass_assignment_security/sanitizer.rb
92
+ - lib/active_model/mass_assignment_security.rb
94
93
  - lib/active_model/naming.rb
94
+ - lib/active_model/observer_array.rb
95
+ - lib/active_model/observing.rb
95
96
  - lib/active_model/railtie.rb
96
97
  - lib/active_model/secure_password.rb
98
+ - lib/active_model/serialization.rb
99
+ - lib/active_model/serializers/json.rb
100
+ - lib/active_model/serializers/xml.rb
101
+ - lib/active_model/test_case.rb
97
102
  - lib/active_model/translation.rb
98
- - lib/active_model/validations.rb
99
- - lib/active_model/callbacks.rb
100
- - lib/active_model/validator.rb
101
- - lib/active_model/validations/validates.rb
102
- - lib/active_model/validations/exclusion.rb
103
- - lib/active_model/validations/confirmation.rb
104
- - lib/active_model/validations/numericality.rb
105
103
  - lib/active_model/validations/acceptance.rb
106
- - lib/active_model/validations/with.rb
107
- - lib/active_model/validations/format.rb
108
104
  - lib/active_model/validations/callbacks.rb
105
+ - lib/active_model/validations/confirmation.rb
106
+ - lib/active_model/validations/exclusion.rb
107
+ - lib/active_model/validations/format.rb
109
108
  - lib/active_model/validations/inclusion.rb
110
109
  - lib/active_model/validations/length.rb
110
+ - lib/active_model/validations/numericality.rb
111
111
  - lib/active_model/validations/presence.rb
112
- - lib/active_model/serializers/xml.rb
113
- - lib/active_model/serializers/json.rb
112
+ - lib/active_model/validations/validates.rb
113
+ - lib/active_model/validations/with.rb
114
+ - lib/active_model/validations.rb
115
+ - lib/active_model/validator.rb
116
+ - lib/active_model/version.rb
117
+ - lib/active_model.rb
114
118
  homepage: http://www.rubyonrails.org
115
119
  licenses: []
116
120
 
@@ -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:
145
- rubygems_version: 1.8.6
151
+ rubygems_version: 1.8.16
146
152
  signing_key:
147
153
  specification_version: 3
148
154
  summary: A toolkit for building modeling frameworks (part of Rails).