activemodel 3.2.22.5 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +85 -64
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +61 -24
  5. data/lib/active_model.rb +21 -11
  6. data/lib/active_model/attribute_methods.rb +150 -125
  7. data/lib/active_model/callbacks.rb +49 -34
  8. data/lib/active_model/conversion.rb +39 -19
  9. data/lib/active_model/deprecated_mass_assignment_security.rb +21 -0
  10. data/lib/active_model/dirty.rb +48 -32
  11. data/lib/active_model/errors.rb +176 -88
  12. data/lib/active_model/forbidden_attributes_protection.rb +27 -0
  13. data/lib/active_model/lint.rb +42 -55
  14. data/lib/active_model/locale/en.yml +3 -1
  15. data/lib/active_model/model.rb +97 -0
  16. data/lib/active_model/naming.rb +191 -51
  17. data/lib/active_model/railtie.rb +11 -1
  18. data/lib/active_model/secure_password.rb +55 -25
  19. data/lib/active_model/serialization.rb +51 -27
  20. data/lib/active_model/serializers/json.rb +83 -46
  21. data/lib/active_model/serializers/xml.rb +46 -12
  22. data/lib/active_model/test_case.rb +0 -12
  23. data/lib/active_model/translation.rb +9 -10
  24. data/lib/active_model/validations.rb +154 -52
  25. data/lib/active_model/validations/absence.rb +31 -0
  26. data/lib/active_model/validations/acceptance.rb +10 -22
  27. data/lib/active_model/validations/callbacks.rb +78 -25
  28. data/lib/active_model/validations/clusivity.rb +41 -0
  29. data/lib/active_model/validations/confirmation.rb +13 -23
  30. data/lib/active_model/validations/exclusion.rb +26 -55
  31. data/lib/active_model/validations/format.rb +44 -34
  32. data/lib/active_model/validations/inclusion.rb +22 -52
  33. data/lib/active_model/validations/length.rb +48 -49
  34. data/lib/active_model/validations/numericality.rb +30 -32
  35. data/lib/active_model/validations/presence.rb +12 -22
  36. data/lib/active_model/validations/validates.rb +68 -36
  37. data/lib/active_model/validations/with.rb +28 -23
  38. data/lib/active_model/validator.rb +22 -22
  39. data/lib/active_model/version.rb +4 -4
  40. metadata +23 -24
  41. data/lib/active_model/mass_assignment_security.rb +0 -237
  42. data/lib/active_model/mass_assignment_security/permission_set.rb +0 -40
  43. data/lib/active_model/mass_assignment_security/sanitizer.rb +0 -59
  44. data/lib/active_model/observer_array.rb +0 -147
  45. data/lib/active_model/observing.rb +0 -252
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 982cc00a572b16d30544a1a24969040bc7251498
4
- data.tar.gz: 0e339f7d10f59eec64a80ff22f4cf39d4777890d
3
+ metadata.gz: a123b304fffb488ab66aab52d5fc0d41b0c0b511
4
+ data.tar.gz: 1890c14c3ab9251044e70e38f993d4c55707cb52
5
5
  SHA512:
6
- metadata.gz: 9d68cb6eef4d157b7db04e67b43fbb2b90231deba15aa7ee8ebe2f7a5db6bb5539673e6f76bc3cc6f2c38395401b981716eaff1f830bfd1a8c308a1012bd232b
7
- data.tar.gz: f472aeea89ec6c3e099c84d89d45d78c24784efe382a8fb5abab61a62f20212caf3328c07254bb93f1cc21dd44c33125a9b0d9ea8157aa62efc3d3d41665207c
6
+ metadata.gz: 882ad1f17ccb90c6a79d86a42d3f91685a1ece5e7ec63ed83be888a20d086ea38928aba2af650e13b79c1955d5f62d78c4b865311be1a8ae065197ee2a858aaa
7
+ data.tar.gz: 5452a0c0afabc7f3c3f536e670cb61244dd8d9236bfac6dd049da917dbe6bed0d110b4c6ed3bd0a374c7e09b42988cd937ae57cef83ff03e42a33aeea2cbb276
data/CHANGELOG.md CHANGED
@@ -1,122 +1,143 @@
1
- ## Rails 3.2.22 (Jun 16, 2015) ##
1
+ ## Rails 4.0.0.beta1 (February 25, 2013) ##
2
2
 
3
- * No changes.
3
+ * Add `ActiveModel::Validations::AbsenceValidator`, a validator to check the
4
+ absence of attributes.
4
5
 
6
+ class Person
7
+ include ActiveModel::Validations
5
8
 
6
- ## Rails 3.2.19 (Jul 2, 2014) ##
9
+ attr_accessor :first_name
10
+ validates_absence_of :first_name
11
+ end
7
12
 
8
- * No changes.
13
+ person = Person.new
14
+ person.first_name = "John"
15
+ person.valid?
16
+ # => false
17
+ person.errors.messages
18
+ # => {:first_name=>["must be blank"]}
9
19
 
20
+ *Roberto Vasquez Angel*
10
21
 
11
- ## Rails 3.2.18 (May 6, 2014) ##
22
+ * `[attribute]_changed?` now returns `false` after a call to `reset_[attribute]!`.
12
23
 
13
- * No changes.
24
+ *Renato Mascarenhas*
14
25
 
26
+ * Observers was extracted from Active Model as `rails-observers` gem.
15
27
 
16
- ## Rails 3.2.17 (Feb 18, 2014) ##
28
+ *Rafael Mendonça França*
17
29
 
18
- * No changes.
30
+ * Specify type of singular association during serialization.
19
31
 
32
+ *Steve Klabnik*
20
33
 
21
- ## Rails 3.2.16 (Dec 3, 2013) ##
34
+ * Fixed length validator to correctly handle `nil`. Fixes #7180.
22
35
 
23
- * No changes.
36
+ *Michal Zima*
24
37
 
38
+ * Removed dispensable `require` statements. Make sure to require `active_model` before requiring
39
+ individual parts of the framework.
25
40
 
26
- ## Rails 3.2.15 (Oct 16, 2013) ##
41
+ *Yves Senn*
27
42
 
28
- * No changes.
43
+ * Use BCrypt's `MIN_COST` in the test environment for speedier tests when using `has_secure_pasword`.
29
44
 
30
- ## Rails 3.2.14 (Jul 22, 2013) ##
45
+ *Brian Cardarella + Jeremy Kemper + Trevor Turk*
31
46
 
32
- * No changes.
47
+ * Add `ActiveModel::ForbiddenAttributesProtection`, a simple module to
48
+ protect attributes from mass assignment when non-permitted attributes are passed.
33
49
 
50
+ *DHH + Guillermo Iguaran*
34
51
 
35
- ## Rails 3.2.13 (Mar 18, 2013) ##
52
+ * `ActiveModel::MassAssignmentSecurity` has been extracted from Active Model and the
53
+ `protected_attributes` gem should be added to Gemfile in order to use
54
+ `attr_accessible` and `attr_protected` macros in your models.
36
55
 
37
- * Specify type of singular association during serialization *Steve Klabnik*
56
+ *Guillermo Iguaran*
38
57
 
39
-
40
- ## Rails 3.2.12 (Feb 11, 2013) ##
41
-
42
- * Fix issue with `attr_protected` where malformed input could circumvent protection.
43
- CVE-2013-0276
44
-
45
- *joernchen*
46
-
47
-
48
- ## Rails 3.2.11 (Jan 8, 2013) ##
49
-
50
- * No changes.
51
-
52
-
53
- ## Rails 3.2.10 (Jan 2, 2013) ##
54
-
55
- * No changes.
56
-
57
-
58
- ## Rails 3.2.9 (Nov 12, 2012) ##
59
-
60
- * Due to a change in builder, nil values and empty strings now generates
58
+ * Due to a change in builder, `nil` and empty strings now generate
61
59
  closed tags, so instead of this:
62
60
 
63
61
  <pseudonyms nil=\"true\"></pseudonyms>
64
62
 
65
- It generates this:
63
+ it generates this:
66
64
 
67
65
  <pseudonyms nil=\"true\"/>
68
66
 
69
67
  *Carlos Antonio da Silva*
70
68
 
69
+ * Inclusion/exclusion validators accept a method name passed as a symbol to the
70
+ `:in` option.
71
71
 
72
- ## Rails 3.2.8 (Aug 9, 2012) ##
73
-
74
- * No changes.
75
-
72
+ This allows to use dynamic inclusion/exclusion values using methods, besides
73
+ the current lambda/proc support.
76
74
 
77
- ## Rails 3.2.7 (Jul 26, 2012) ##
75
+ *Gabriel Sobrinho*
78
76
 
79
- * `validates_inclusion_of` and `validates_exclusion_of` now accept `:within` option as alias of `:in` as documented.
77
+ * `ActiveModel::Validation#validates` ability to pass custom exception to the
78
+ `:strict` option.
80
79
 
81
- * Fix the the backport of the object dup with the ruby 1.9.3p194.
80
+ *Bogdan Gusiev*
82
81
 
82
+ * Changed `ActiveModel::Serializers::Xml::Serializer#add_associations` to by default
83
+ propagate `:skip_types, :dasherize, :camelize` keys to included associations.
84
+ It can be overriden on each association by explicitly specifying the option on one
85
+ or more associations
83
86
 
84
- ## Rails 3.2.6 (Jun 12, 2012) ##
87
+ *Anthony Alberto*
85
88
 
86
- * No changes.
89
+ * Changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to false.
90
+ Now, AM Serializers and AR objects have the same default behaviour. Fixes #6578.
87
91
 
92
+ class User < ActiveRecord::Base; end
88
93
 
89
- ## Rails 3.2.4 (May 31, 2012) ##
94
+ class Person
95
+ include ActiveModel::Model
96
+ include ActiveModel::AttributeMethods
97
+ include ActiveModel::Serializers::JSON
90
98
 
91
- * No changes.
99
+ attr_accessor :name, :age
92
100
 
101
+ def attributes
102
+ instance_values
103
+ end
104
+ end
93
105
 
94
- ## Rails 3.2.3 (March 30, 2012) ##
106
+ user.as_json
107
+ => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
108
+ # root is not included
95
109
 
96
- * No changes.
110
+ person.as_json
111
+ => {"name"=>"Francesco", "age"=>22}
112
+ # root is not included
97
113
 
114
+ *Francesco Rodriguez*
98
115
 
99
- ## Rails 3.2.2 (March 1, 2012) ##
116
+ * Passing false hash values to `validates` will no longer enable the corresponding validators.
100
117
 
101
- * No changes.
118
+ *Steve Purcell*
102
119
 
120
+ * `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute`.
103
121
 
104
- ## Rails 3.2.1 (January 26, 2012) ##
122
+ *Brian Cardarella*
105
123
 
106
- * No changes.
124
+ * Added `ActiveModel::Model`, a mixin to make Ruby objects work with AP out of box.
107
125
 
126
+ *Guillermo Iguaran*
108
127
 
109
- ## Rails 3.2.0 (January 20, 2012) ##
128
+ * `AM::Errors#to_json`: support `:full_messages` parameter.
110
129
 
111
- * Deprecated `define_attr_method` in `ActiveModel::AttributeMethods`, because this only existed to
112
- support methods like `set_table_name` in Active Record, which are themselves being deprecated. *Jon Leighton*
130
+ *Bogdan Gusiev*
113
131
 
114
- * Add ActiveModel::Errors#added? to check if a specific error has been added *Martin Svalin*
132
+ * Trim down Active Model API by removing `valid?` and `errors.full_messages`.
115
133
 
116
- * Add ability to define strict validation(with :strict => true option) that always raises exception when fails *Bogdan Gusiev*
134
+ *José Valim*
117
135
 
118
- * Deprecate "Model.model_name.partial_path" in favor of "model.to_partial_path" *Grant Hutchins, Peter Jaros*
136
+ * When `^` or `$` are used in the regular expression provided to `validates_format_of`
137
+ and the `:multiline` option is not set to true, an exception will be raised. This is
138
+ to prevent security vulnerabilities when using `validates_format_of`. The problem is
139
+ described in detail in the Rails security guide.
119
140
 
120
- * Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior *Bogdan Gusiev*
141
+ *Jan Berdajs + Egor Homakov*
121
142
 
122
- Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activemodel/CHANGELOG.md) for previous changes.
143
+ Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activemodel/CHANGELOG.md) for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2011 David Heinemeier Hansson
1
+ Copyright (c) 2004-2013 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = Active Model -- model interfaces for Rails
2
2
 
3
3
  Active Model provides a known set of interfaces for usage in model classes.
4
- They allow for Action Pack helpers to interact with non-ActiveRecord models,
4
+ They allow for Action Pack helpers to interact with non-Active Record models,
5
5
  for example. Active Model also helps building custom ORMs for use outside of
6
6
  the Rails framework.
7
7
 
@@ -9,10 +9,31 @@ Prior to Rails 3.0, if a plugin or gem developer wanted to have an object
9
9
  interact with Action Pack helpers, it was required to either copy chunks of
10
10
  code from Rails, or monkey patch entire helpers to make them handle objects
11
11
  that did not exactly conform to the Active Record interface. This would result
12
- in code duplication and fragile applications that broke on upgrades.
12
+ in code duplication and fragile applications that broke on upgrades. Active
13
+ Model solves this by defining an explicit API. You can read more about the
14
+ API in <tt>ActiveModel::Lint::Tests</tt>.
13
15
 
14
- Active Model solves this. You can include functionality from the following
15
- modules:
16
+ Active Model provides a default module that implements the basic API required
17
+ to integrate with Action Pack out of the box: <tt>ActiveModel::Model</tt>.
18
+
19
+ class Person
20
+ include ActiveModel::Model
21
+
22
+ attr_accessor :name, :age
23
+ validates_presence_of :name
24
+ end
25
+
26
+ person = Person.new(name: 'bob', age: '18')
27
+ person.name # => 'bob'
28
+ person.age # => '18'
29
+ person.valid? # => true
30
+
31
+ It includes model name introspections, conversions, translations and
32
+ validations, resulting in a class suitable to be used with Action Pack.
33
+ See <tt>ActiveModel::Model</tt> for more examples.
34
+
35
+ Active Model also provides the following functionality to have ORM-like
36
+ behavior out of the box:
16
37
 
17
38
  * Add attribute magic to objects
18
39
 
@@ -20,7 +41,7 @@ modules:
20
41
  include ActiveModel::AttributeMethods
21
42
 
22
43
  attribute_method_prefix 'clear_'
23
- define_attribute_methods [:name, :age]
44
+ define_attribute_methods :name, :age
24
45
 
25
46
  attr_accessor :name, :age
26
47
 
@@ -54,7 +75,11 @@ modules:
54
75
 
55
76
  * Tracking value changes
56
77
 
57
- The ActiveModel::Dirty module allows for tracking attribute changes:
78
+ class Person
79
+ include ActiveModel::Dirty
80
+
81
+ attr_accessor :name
82
+ end
58
83
 
59
84
  person = Person.new
60
85
  person.name # => nil
@@ -87,18 +112,14 @@ modules:
87
112
  errors.add(:name, "can not be nil") if name.nil?
88
113
  end
89
114
 
90
- def ErrorsPerson.human_attribute_name(attr, options = {})
115
+ def self.human_attribute_name(attr, options = {})
91
116
  "Name"
92
117
  end
93
-
94
118
  end
95
119
 
96
120
  person.errors.full_messages
97
121
  # => ["Name can not be nil"]
98
122
 
99
- person.errors.full_messages
100
- # => ["Name can not be nil"]
101
-
102
123
  {Learn more}[link:classes/ActiveModel/Errors.html]
103
124
 
104
125
  * Model name introspection
@@ -112,22 +133,36 @@ modules:
112
133
 
113
134
  {Learn more}[link:classes/ActiveModel/Naming.html]
114
135
 
115
- * Observer support
116
-
117
- ActiveModel::Observers allows your object to implement the Observer
118
- pattern in a Rails App and take advantage of all the standard observer
119
- functions.
120
-
121
- {Learn more}[link:classes/ActiveModel/Observer.html]
122
-
123
136
  * Making objects serializable
124
137
 
125
138
  ActiveModel::Serialization provides a standard interface for your object
126
139
  to provide +to_json+ or +to_xml+ serialization.
127
140
 
141
+ class SerialPerson
142
+ include ActiveModel::Serialization
143
+
144
+ attr_accessor :name
145
+
146
+ def attributes
147
+ {'name' => name}
148
+ end
149
+ end
150
+
128
151
  s = SerialPerson.new
129
152
  s.serializable_hash # => {"name"=>nil}
153
+
154
+ class SerialPerson
155
+ include ActiveModel::Serializers::JSON
156
+ end
157
+
158
+ s = SerialPerson.new
130
159
  s.to_json # => "{\"name\":null}"
160
+
161
+ class SerialPerson
162
+ include ActiveModel::Serializers::Xml
163
+ end
164
+
165
+ s = SerialPerson.new
131
166
  s.to_xml # => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<serial-person...
132
167
 
133
168
  {Learn more}[link:classes/ActiveModel/Serialization.html]
@@ -163,7 +198,7 @@ modules:
163
198
 
164
199
  * Custom validators
165
200
 
166
- class Person
201
+ class ValidatorPerson
167
202
  include ActiveModel::Validations
168
203
  validates_with HasNameValidator
169
204
  attr_accessor :name
@@ -171,7 +206,7 @@ modules:
171
206
 
172
207
  class HasNameValidator < ActiveModel::Validator
173
208
  def validate(record)
174
- record.errors[:name] = "must exist" if record.name.blank?
209
+ record.errors[:name] = "must exist" if record.name.blank?
175
210
  end
176
211
  end
177
212
 
@@ -182,7 +217,7 @@ modules:
182
217
  p.valid? # => true
183
218
 
184
219
  {Learn more}[link:classes/ActiveModel/Validator.html]
185
-
220
+
186
221
 
187
222
  == Download and installation
188
223
 
@@ -192,12 +227,14 @@ The latest version of Active Model can be installed with RubyGems:
192
227
 
193
228
  Source code can be downloaded as part of the Rails project on GitHub
194
229
 
195
- * https://github.com/rails/rails/tree/3-2-stable/activemodel
230
+ * https://github.com/rails/rails/tree/master/activemodel
196
231
 
197
232
 
198
233
  == License
199
234
 
200
- Active Model is released under the MIT license.
235
+ Active Model is released under the MIT license:
236
+
237
+ * http://www.opensource.org/licenses/MIT
201
238
 
202
239
 
203
240
  == Support
data/lib/active_model.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2011 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2013 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,9 +21,8 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
25
- $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
26
24
  require 'active_support'
25
+ require 'active_support/rails'
27
26
  require 'active_model/version'
28
27
 
29
28
  module ActiveModel
@@ -35,13 +34,12 @@ module ActiveModel
35
34
  autoload :Conversion
36
35
  autoload :Dirty
37
36
  autoload :EachValidator, 'active_model/validator'
38
- autoload :Errors
37
+ autoload :ForbiddenAttributesProtection
39
38
  autoload :Lint
40
- autoload :MassAssignmentSecurity
39
+ autoload :Model
40
+ autoload :DeprecatedMassAssignmentSecurity
41
41
  autoload :Name, 'active_model/naming'
42
42
  autoload :Naming
43
- autoload :Observer, 'active_model/observing'
44
- autoload :Observing
45
43
  autoload :SecurePassword
46
44
  autoload :Serialization
47
45
  autoload :TestCase
@@ -49,13 +47,25 @@ module ActiveModel
49
47
  autoload :Validations
50
48
  autoload :Validator
51
49
 
50
+ eager_autoload do
51
+ autoload :Errors
52
+ end
53
+
52
54
  module Serializers
53
55
  extend ActiveSupport::Autoload
54
56
 
55
- autoload :JSON
56
- autoload :Xml
57
+ eager_autoload do
58
+ autoload :JSON
59
+ autoload :Xml
60
+ end
61
+ end
62
+
63
+ def eager_load!
64
+ super
65
+ ActiveModel::Serializer.eager_load!
57
66
  end
58
67
  end
59
68
 
60
- require 'active_support/i18n'
61
- I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
69
+ ActiveSupport.on_load(:i18n) do
70
+ I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
71
+ end