activemodel 5.1.7 → 5.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +32 -93
  3. data/README.rdoc +1 -1
  4. data/lib/active_model.rb +6 -1
  5. data/lib/active_model/attribute.rb +243 -0
  6. data/lib/active_model/attribute/user_provided_default.rb +30 -0
  7. data/lib/active_model/attribute_assignment.rb +8 -5
  8. data/lib/active_model/attribute_methods.rb +12 -10
  9. data/lib/active_model/attribute_mutation_tracker.rb +116 -0
  10. data/lib/active_model/attribute_set.rb +113 -0
  11. data/lib/active_model/attribute_set/builder.rb +124 -0
  12. data/lib/active_model/attribute_set/yaml_encoder.rb +41 -0
  13. data/lib/active_model/attributes.rb +108 -0
  14. data/lib/active_model/callbacks.rb +7 -2
  15. data/lib/active_model/conversion.rb +2 -0
  16. data/lib/active_model/dirty.rb +124 -57
  17. data/lib/active_model/errors.rb +32 -21
  18. data/lib/active_model/forbidden_attributes_protection.rb +2 -0
  19. data/lib/active_model/gem_version.rb +5 -3
  20. data/lib/active_model/lint.rb +2 -0
  21. data/lib/active_model/model.rb +2 -0
  22. data/lib/active_model/naming.rb +5 -3
  23. data/lib/active_model/railtie.rb +2 -0
  24. data/lib/active_model/secure_password.rb +5 -3
  25. data/lib/active_model/serialization.rb +2 -0
  26. data/lib/active_model/serializers/json.rb +3 -2
  27. data/lib/active_model/translation.rb +2 -0
  28. data/lib/active_model/type.rb +6 -0
  29. data/lib/active_model/type/big_integer.rb +2 -0
  30. data/lib/active_model/type/binary.rb +2 -0
  31. data/lib/active_model/type/boolean.rb +2 -0
  32. data/lib/active_model/type/date.rb +2 -0
  33. data/lib/active_model/type/date_time.rb +6 -0
  34. data/lib/active_model/type/decimal.rb +2 -0
  35. data/lib/active_model/type/float.rb +2 -0
  36. data/lib/active_model/type/helpers.rb +2 -0
  37. data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +6 -0
  38. data/lib/active_model/type/helpers/mutable.rb +2 -0
  39. data/lib/active_model/type/helpers/numeric.rb +2 -0
  40. data/lib/active_model/type/helpers/time_value.rb +2 -1
  41. data/lib/active_model/type/immutable_string.rb +2 -0
  42. data/lib/active_model/type/integer.rb +3 -1
  43. data/lib/active_model/type/registry.rb +2 -0
  44. data/lib/active_model/type/string.rb +2 -0
  45. data/lib/active_model/type/time.rb +8 -4
  46. data/lib/active_model/type/value.rb +3 -1
  47. data/lib/active_model/validations.rb +7 -3
  48. data/lib/active_model/validations/absence.rb +2 -0
  49. data/lib/active_model/validations/acceptance.rb +2 -0
  50. data/lib/active_model/validations/callbacks.rb +11 -13
  51. data/lib/active_model/validations/clusivity.rb +2 -0
  52. data/lib/active_model/validations/confirmation.rb +3 -1
  53. data/lib/active_model/validations/exclusion.rb +2 -0
  54. data/lib/active_model/validations/format.rb +1 -0
  55. data/lib/active_model/validations/helper_methods.rb +2 -0
  56. data/lib/active_model/validations/inclusion.rb +2 -0
  57. data/lib/active_model/validations/length.rb +10 -2
  58. data/lib/active_model/validations/numericality.rb +3 -1
  59. data/lib/active_model/validations/presence.rb +1 -0
  60. data/lib/active_model/validations/validates.rb +4 -3
  61. data/lib/active_model/validations/with.rb +2 -0
  62. data/lib/active_model/validator.rb +6 -4
  63. data/lib/active_model/version.rb +2 -0
  64. metadata +17 -9
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_model/validations/clusivity"
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module ActiveModel
3
4
  module Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  module Validations
3
5
  module HelperMethods # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_model/validations/clusivity"
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  module Validations
3
5
  class LengthValidator < EachValidator # :nodoc:
@@ -29,8 +31,8 @@ module ActiveModel
29
31
  keys.each do |key|
30
32
  value = options[key]
31
33
 
32
- unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY
33
- raise ArgumentError, ":#{key} must be a nonnegative Integer or Infinity"
34
+ unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY || value.is_a?(Symbol) || value.is_a?(Proc)
35
+ raise ArgumentError, ":#{key} must be a nonnegative Integer, Infinity, Symbol, or Proc"
34
36
  end
35
37
  end
36
38
  end
@@ -43,6 +45,12 @@ module ActiveModel
43
45
  next unless check_value = options[key]
44
46
 
45
47
  if !value.nil? || skip_nil_check?(key)
48
+ case check_value
49
+ when Proc
50
+ check_value = check_value.call(record)
51
+ when Symbol
52
+ check_value = record.send(check_value)
53
+ end
46
54
  next if value_length.send(validity_check, check_value)
47
55
  end
48
56
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  module Validations
3
5
  class NumericalityValidator < EachValidator # :nodoc:
@@ -106,7 +108,7 @@ module ActiveModel
106
108
  module HelperMethods
107
109
  # Validates whether the value of the specified attribute is numeric by
108
110
  # trying to convert it to a float with Kernel.Float (if <tt>only_integer</tt>
109
- # is +false+) or applying it to the regular expression <tt>/\A[\+\-]?\d+\Z/</tt>
111
+ # is +false+) or applying it to the regular expression <tt>/\A[\+\-]?\d+\z/</tt>
110
112
  # (if <tt>only_integer</tt> is set to +true+).
111
113
  #
112
114
  # class Person < ActiveRecord::Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module ActiveModel
3
4
  module Validations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/hash/slice"
2
4
 
3
5
  module ActiveModel
@@ -18,7 +20,6 @@ module ActiveModel
18
20
  # validates :first_name, length: { maximum: 30 }
19
21
  # validates :age, numericality: true
20
22
  # validates :username, presence: true
21
- # validates :username, uniqueness: true
22
23
  #
23
24
  # The power of the +validates+ method comes when using custom validators
24
25
  # and default validators in one call for a given attribute.
@@ -34,7 +35,7 @@ module ActiveModel
34
35
  # include ActiveModel::Validations
35
36
  # attr_accessor :name, :email
36
37
  #
37
- # validates :name, presence: true, uniqueness: true, length: { maximum: 100 }
38
+ # validates :name, presence: true, length: { maximum: 100 }
38
39
  # validates :email, presence: true, email: true
39
40
  # end
40
41
  #
@@ -94,7 +95,7 @@ module ActiveModel
94
95
  # Example:
95
96
  #
96
97
  # validates :password, presence: true, confirmation: true, if: :password_required?
97
- # validates :token, uniqueness: true, strict: TokenGenerationException
98
+ # validates :token, length: 24, strict: TokenLengthException
98
99
  #
99
100
  #
100
101
  # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+, +:strict+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/array/extract_options"
2
4
 
3
5
  module ActiveModel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/anonymous"
2
4
 
3
5
  module ActiveModel
@@ -82,7 +84,7 @@ module ActiveModel
82
84
  # end
83
85
  #
84
86
  # It can be useful to access the class that is using that validator when there are prerequisites such
85
- # as an +attr_accessor+ being present. This class is accessible via +options[:class]+ in the constructor.
87
+ # as an +attr_accessor+ being present. This class is accessible via <tt>options[:class]</tt> in the constructor.
86
88
  # To setup your validator override the constructor.
87
89
  #
88
90
  # class MyValidator < ActiveModel::Validator
@@ -97,7 +99,7 @@ module ActiveModel
97
99
  # Returns the kind of the validator.
98
100
  #
99
101
  # PresenceValidator.kind # => :presence
100
- # UniquenessValidator.kind # => :uniqueness
102
+ # AcceptanceValidator.kind # => :acceptance
101
103
  def self.kind
102
104
  @kind ||= name.split("::").last.underscore.chomp("_validator").to_sym unless anonymous?
103
105
  end
@@ -109,8 +111,8 @@ module ActiveModel
109
111
 
110
112
  # Returns the kind for this validator.
111
113
  #
112
- # PresenceValidator.new.kind # => :presence
113
- # UniquenessValidator.new.kind # => :uniqueness
114
+ # PresenceValidator.new(attributes: [:username]).kind # => :presence
115
+ # AcceptanceValidator.new(attributes: [:terms]).kind # => :acceptance
114
116
  def kind
115
117
  self.class.kind
116
118
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "gem_version"
2
4
 
3
5
  module ActiveModel
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.7
4
+ version: 5.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.7
19
+ version: 5.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.7
26
+ version: 5.2.0.beta1
27
27
  description: A toolkit for building modeling frameworks like Active Record. Rich support
28
28
  for attributes, callbacks, validations, serialization, internationalization, and
29
29
  testing.
@@ -36,8 +36,15 @@ files:
36
36
  - MIT-LICENSE
37
37
  - README.rdoc
38
38
  - lib/active_model.rb
39
+ - lib/active_model/attribute.rb
40
+ - lib/active_model/attribute/user_provided_default.rb
39
41
  - lib/active_model/attribute_assignment.rb
40
42
  - lib/active_model/attribute_methods.rb
43
+ - lib/active_model/attribute_mutation_tracker.rb
44
+ - lib/active_model/attribute_set.rb
45
+ - lib/active_model/attribute_set/builder.rb
46
+ - lib/active_model/attribute_set/yaml_encoder.rb
47
+ - lib/active_model/attributes.rb
41
48
  - lib/active_model/callbacks.rb
42
49
  - lib/active_model/conversion.rb
43
50
  - lib/active_model/dirty.rb
@@ -93,8 +100,8 @@ homepage: http://rubyonrails.org
93
100
  licenses:
94
101
  - MIT
95
102
  metadata:
96
- source_code_uri: https://github.com/rails/rails/tree/v5.1.7/activemodel
97
- changelog_uri: https://github.com/rails/rails/blob/v5.1.7/activemodel/CHANGELOG.md
103
+ source_code_uri: https://github.com/rails/rails/tree/v5.2.0.beta1/activemodel
104
+ changelog_uri: https://github.com/rails/rails/blob/v5.2.0.beta1/activemodel/CHANGELOG.md
98
105
  post_install_message:
99
106
  rdoc_options: []
100
107
  require_paths:
@@ -106,11 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
113
  version: 2.2.2
107
114
  required_rubygems_version: !ruby/object:Gem::Requirement
108
115
  requirements:
109
- - - ">="
116
+ - - ">"
110
117
  - !ruby/object:Gem::Version
111
- version: '0'
118
+ version: 1.3.1
112
119
  requirements: []
113
- rubygems_version: 3.0.1
120
+ rubyforge_project:
121
+ rubygems_version: 2.6.12
114
122
  signing_key:
115
123
  specification_version: 4
116
124
  summary: A toolkit for building modeling frameworks (part of Rails).