reform-rails 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43ce92d480a18dfc398266771235ed677f949aaefef85fca362c787d49b3443b
4
- data.tar.gz: f6d7d3f34e15f3ee674aacdba842cc0f42d43850f71dbc29d24704903342427a
3
+ metadata.gz: 11444b229bdc2a6b09fc130b3ce39b799be05f9caf0b6ced962cb9162651de05
4
+ data.tar.gz: 15b2965904cf1083b20a682feb667fe3a44dee3f5f424235b62ffae4e6297eef
5
5
  SHA512:
6
- metadata.gz: 51d6a79615a1b7e4d191c80a3be1584f7e719f7c1907583600225c160938400ecdfac6b616440669f49c0b98bf3f36224bfb2f9a2355e94cd994be16355bfcf9
7
- data.tar.gz: 95904bb3946944f63c6c802191dbd91b95e8d9d663a8dc2c8665ac1f94a9f863a729c27606e79be2e5cf960b6a4c8c54aa50a08be8357b6c354bf2e5522e4edd
6
+ metadata.gz: f405809a0c4e33711233bdff60a14ad6c87b0a8e90b94a71b025a5dbb2025b3c3bea9d0b6c6e4c51f20afd4ad06bb513d8ab0d134f6ee22da2545a8436d8e141
7
+ data.tar.gz: 6c975e0e7c4d66124e909a1ae73b7415e95886a46fda82164dd55eb6f36603a0d69c8ebc9e39ab8a4793e213c59d14c1c30e9f502b8192e81a33e39cdd776127
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.3.1
2
+
3
+ * Fix: ActiveModel acceptance validator wasn't properly monkey patched
4
+ Now this will work in environments where active model and active record is
5
+ not loaded by default. In addition, it will work with all the Rails versions
6
+ we support
7
+
1
8
  # 0.3.0
2
9
 
3
10
  * Add `conditions` option to Reform Uniqueness validation.
@@ -0,0 +1,36 @@
1
+ module Reform::Form::ActiveModel
2
+ module AcceptanceValidatorPatch
3
+ def self.apply!
4
+ return if defined?(::ActiveModel::Validations::ReformAcceptanceValidator)
5
+
6
+ klass = Class.new(::ActiveModel::EachValidator) do
7
+ def initialize(options)
8
+ super({ allow_nil: true, accept: ["1", true] }.merge!(options))
9
+ end
10
+
11
+ def validate_each(record, attribute, value)
12
+ unless acceptable_option?(value)
13
+ if Gem::Version.new(::ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
14
+ record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
15
+ else
16
+ record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def acceptable_option?(value)
24
+ Array(options[:accept]).include?(value)
25
+ end
26
+ end
27
+
28
+ # Assign the class to a constant for tracking
29
+ ::ActiveModel::Validations.const_set(:ReformAcceptanceValidator, klass)
30
+
31
+ # Override the built-in validator
32
+ ::ActiveModel::Validations.send(:remove_const, :AcceptanceValidator)
33
+ ::ActiveModel::Validations.const_set(:AcceptanceValidator, klass)
34
+ end
35
+ end
36
+ end
@@ -57,6 +57,17 @@ module Reform
57
57
  include Reform::Form::Dry
58
58
  end
59
59
  end
60
+
61
+ initializer "reform.patch_acceptance_validator" do
62
+ require "reform/form/active_model/acceptance_validator_patch"
63
+
64
+ if defined?(::ActiveModel::Validations::AcceptanceValidator)
65
+ Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply!
66
+ else
67
+ ActiveSupport.on_load(:active_record) { Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply! }
68
+ Rails.application.config.to_prepare { Reform::Form::ActiveModel::AcceptanceValidatorPatch.apply! }
69
+ end
70
+ end
60
71
  end # Railtie
61
72
  end
62
73
  end
@@ -1,5 +1,5 @@
1
1
  module Reform
2
2
  module Rails
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
data/lib/reform/rails.rb CHANGED
@@ -4,29 +4,3 @@ require "reform/rails/railtie"
4
4
 
5
5
  module Reform
6
6
  end
7
-
8
- module ActiveModel
9
- module Validations
10
- class AcceptanceValidator < EachValidator # :nodoc:
11
- def initialize(options)
12
- super({ allow_nil: true, accept: ["1", true] }.merge!(options))
13
- end
14
-
15
- def validate_each(record, attribute, value)
16
- unless acceptable_option?(value)
17
- if Gem::Version.new(ActiveModel::VERSION::STRING) >= Gem::Version.new('6.1.0')
18
- record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
19
- else
20
- record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
21
- end
22
- end
23
- end
24
-
25
- private
26
-
27
- def acceptable_option?(value)
28
- Array(options[:accept]).include?(value)
29
- end
30
- end
31
- end
32
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-26 00:00:00.000000000 Z
11
+ date: 2025-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform
@@ -109,6 +109,7 @@ files:
109
109
  - Rakefile
110
110
  - lib/reform/active_record.rb
111
111
  - lib/reform/form/active_model.rb
112
+ - lib/reform/form/active_model/acceptance_validator_patch.rb
112
113
  - lib/reform/form/active_model/form_builder_methods.rb
113
114
  - lib/reform/form/active_model/model_reflections.rb
114
115
  - lib/reform/form/active_model/model_validations.rb
@@ -128,7 +129,7 @@ homepage: https://github.com/trailblazer/reform-rails
128
129
  licenses:
129
130
  - MIT
130
131
  metadata: {}
131
- post_install_message:
132
+ post_install_message:
132
133
  rdoc_options: []
133
134
  require_paths:
134
135
  - lib
@@ -143,8 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
146
  requirements: []
146
- rubygems_version: 3.0.3.1
147
- signing_key:
147
+ rubygems_version: 3.3.27
148
+ signing_key:
148
149
  specification_version: 4
149
150
  summary: Automatically load and include all common Rails form features.
150
151
  test_files: []