reform 2.5.0 → 2.6.0
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 +4 -4
- data/.github/workflows/ci.yml +17 -0
- data/CHANGES.md +6 -0
- data/lib/reform/form/dry.rb +2 -2
- data/lib/reform/form/populator.rb +13 -3
- data/lib/reform/form/prepopulate.rb +1 -1
- data/lib/reform/form/validate.rb +3 -3
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +2 -2
- data/test/populate_test.rb +24 -0
- data/test/prepopulator_test.rb +1 -1
- metadata +10 -16
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a0dc23a8d6a5ba78556fdd827acdfdd596e45dc8354ed5e82acfdfaf5cf5dcf
|
4
|
+
data.tar.gz: 21216fc1a7d500ca8ecd7b59349166629e8ef8514d34d321d23eb5a857d378dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a8aeaa19e8a90c4d0276fba8fe6d85fb5574607e838e9c9298d556292182231ed7d2e29b24835f3265cabb9b37db93f6602388052889e6fcd759e5478ca6ef
|
7
|
+
data.tar.gz: c69fadd4887bfb63538d69a501ddf0e958bd9594ceb9ff97a4181c5017d1eec0a2bbc88fc9cb9ba417257be6f01ac655301b0e822c6babf36ca45d7b7c3fd4e3
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
strategy:
|
6
|
+
fail-fast: false
|
7
|
+
matrix:
|
8
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
9
|
+
ruby: [2.4, 2.5, 2.6, 2.7, '3.0', head]
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby }}
|
16
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
17
|
+
- run: bundle exec rake
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 2.6.0
|
2
|
+
|
3
|
+
* Support ruby-3 by using `Representable::Option` to handle `keyword_arguments` forwarding :tada:
|
4
|
+
* Upgrade `representable` and `disposable` dependencies which uses `trailblazer-option` over `declarative-option`.
|
5
|
+
* Deprecate populator's callable signature which accepts `form` as a separate positional argument. Make all callable (proc, method, `Uber::Callable`) signatures identical.
|
6
|
+
|
1
7
|
## 2.5.0
|
2
8
|
* fix memory leak with Dry validation (#525)
|
3
9
|
|
data/lib/reform/form/dry.rb
CHANGED
@@ -28,7 +28,7 @@ module Reform::Form::Dry
|
|
28
28
|
class Group
|
29
29
|
include InputHash
|
30
30
|
|
31
|
-
def initialize(
|
31
|
+
def initialize(options)
|
32
32
|
@validator = options.fetch(:contract, Contract)
|
33
33
|
@schema_inject_params = options.fetch(:with, {})
|
34
34
|
end
|
@@ -46,7 +46,7 @@ module Reform::Form::Dry
|
|
46
46
|
|
47
47
|
dynamic_options = { form: form }
|
48
48
|
inject_options = schema_inject_params.merge(dynamic_options)
|
49
|
-
contract.new(inject_options).call(input_hash(form))
|
49
|
+
contract.new(**inject_options).call(input_hash(form))
|
50
50
|
end
|
51
51
|
|
52
52
|
def contract
|
@@ -7,7 +7,7 @@
|
|
7
7
|
class Reform::Form::Populator
|
8
8
|
def initialize(user_proc)
|
9
9
|
@user_proc = user_proc # the actual `populator: ->{}` block from the user, via ::property.
|
10
|
-
@value =
|
10
|
+
@value = ::Representable::Option(user_proc) # we can now process Callable, procs, :symbol.
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(input, options)
|
@@ -30,7 +30,17 @@ class Reform::Form::Populator
|
|
30
30
|
|
31
31
|
def call!(options)
|
32
32
|
form = options[:represented]
|
33
|
-
|
33
|
+
evaluate_option(form, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def evaluate_option(form, options)
|
37
|
+
if @user_proc.is_a?(Uber::Callable) && @user_proc.method(:call).arity == 2 # def call(form, options)
|
38
|
+
warn %{[Reform] Accepting `form` as a positional argument in `:populator` will be deprecated. Please use `def call(form:, **options)` signature instead.}
|
39
|
+
|
40
|
+
return @value.(form, exec_context: form, keyword_arguments: options)
|
41
|
+
end
|
42
|
+
|
43
|
+
@value.(exec_context: form, keyword_arguments: options.merge(form: form)) # Representable::Option call
|
34
44
|
end
|
35
45
|
|
36
46
|
def handle_fail(twin, options)
|
@@ -66,7 +76,7 @@ class Reform::Form::Populator
|
|
66
76
|
return @user_proc.new if @user_proc.is_a?(Class) # handle populate_if_empty: Class. this excludes using Callables, though.
|
67
77
|
|
68
78
|
deprecate_positional_args(form, @user_proc, options) do
|
69
|
-
|
79
|
+
evaluate_option(form, options)
|
70
80
|
end
|
71
81
|
end
|
72
82
|
|
@@ -13,7 +13,7 @@ module Reform::Form::Prepopulate
|
|
13
13
|
def prepopulate_local!(options)
|
14
14
|
schema.each do |dfn|
|
15
15
|
next unless block = dfn[:prepopulator]
|
16
|
-
|
16
|
+
::Representable::Option(block).(exec_context: self, keyword_arguments: options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
data/lib/reform/form/validate.rb
CHANGED
@@ -4,15 +4,15 @@ module Reform::Form::Validate
|
|
4
4
|
class AllBlank
|
5
5
|
include Uber::Callable
|
6
6
|
|
7
|
-
def call(
|
7
|
+
def call(input:, binding:, **)
|
8
8
|
# TODO: Schema should provide property names as plain list.
|
9
9
|
# ensure param keys are strings.
|
10
|
-
params =
|
10
|
+
params = input.each_with_object({}) { |(k, v), hash|
|
11
11
|
hash[k.to_s] = v
|
12
12
|
}
|
13
13
|
|
14
14
|
# return false if any property inputs are populated.
|
15
|
-
|
15
|
+
binding[:nested].definitions.each do |definition|
|
16
16
|
value = params[definition.name.to_s]
|
17
17
|
return false if (!value.nil? && value != '')
|
18
18
|
end
|
data/lib/reform/version.rb
CHANGED
data/reform.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "disposable", "
|
21
|
-
spec.add_dependency "representable", ">=
|
20
|
+
spec.add_dependency "disposable", "~> 0.5.0"
|
21
|
+
spec.add_dependency "representable", ">= 3.1.1", "< 3.2.0"
|
22
22
|
spec.add_dependency "uber", "< 0.2.0"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler"
|
data/test/populate_test.rb
CHANGED
@@ -127,6 +127,14 @@ class PopulateWithCallableTest < Minitest::Spec
|
|
127
127
|
class TitlePopulator
|
128
128
|
include Uber::Callable
|
129
129
|
|
130
|
+
def call(form:, **options)
|
131
|
+
form.title = options[:fragment].reverse
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class TitlePopulatorWithOldSignature
|
136
|
+
include Uber::Callable
|
137
|
+
|
130
138
|
def call(form, options)
|
131
139
|
form.title = options[:fragment].reverse
|
132
140
|
end
|
@@ -136,6 +144,10 @@ class PopulateWithCallableTest < Minitest::Spec
|
|
136
144
|
property :title, populator: TitlePopulator.new
|
137
145
|
end
|
138
146
|
|
147
|
+
class AlbumFormWithOldPopulator < TestForm
|
148
|
+
property :title, populator: TitlePopulatorWithOldSignature.new
|
149
|
+
end
|
150
|
+
|
139
151
|
let(:form) { AlbumForm.new(Album.new) }
|
140
152
|
|
141
153
|
it "runs populator method" do
|
@@ -143,6 +155,18 @@ class PopulateWithCallableTest < Minitest::Spec
|
|
143
155
|
|
144
156
|
assert_equal form.title, "!em edirrevo"
|
145
157
|
end
|
158
|
+
|
159
|
+
it "gives warning when `form` is accepted as a positional argument" do
|
160
|
+
_, warnings = capture_io do
|
161
|
+
form = AlbumFormWithOldPopulator.new(Album.new)
|
162
|
+
form.validate("title" => "override me!")
|
163
|
+
|
164
|
+
assert_equal form.title, "!em edirrevo"
|
165
|
+
end
|
166
|
+
|
167
|
+
assert_equal warnings, %{[Reform] Accepting `form` as a positional argument in `:populator` will be deprecated. Please use `def call(form:, **options)` signature instead.
|
168
|
+
}
|
169
|
+
end
|
146
170
|
end
|
147
171
|
|
148
172
|
class PopulateWithProcTest < Minitest::Spec
|
data/test/prepopulator_test.rb
CHANGED
@@ -51,7 +51,7 @@ class PrepopulatorTest < MiniTest::Spec
|
|
51
51
|
|
52
52
|
# add to existing collection.
|
53
53
|
it do
|
54
|
-
form = AlbumForm.new(OpenStruct.new(songs: [Song.new])).prepopulate!
|
54
|
+
form = AlbumForm.new(OpenStruct.new(songs: [Song.new])).prepopulate!(title: "Potemkin City Limits")
|
55
55
|
|
56
56
|
assert_equal form.songs.size, 2
|
57
57
|
assert_equal form.songs[0].model, Song.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
@@ -9,26 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: disposable
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 0.4.2
|
21
|
-
- - "<"
|
18
|
+
- - "~>"
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: 0.5.0
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
|
-
- - "
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: 0.4.2
|
31
|
-
- - "<"
|
25
|
+
- - "~>"
|
32
26
|
- !ruby/object:Gem::Version
|
33
27
|
version: 0.5.0
|
34
28
|
- !ruby/object:Gem::Dependency
|
@@ -37,20 +31,20 @@ dependencies:
|
|
37
31
|
requirements:
|
38
32
|
- - ">="
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
34
|
+
version: 3.1.1
|
41
35
|
- - "<"
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
version: 3.
|
37
|
+
version: 3.2.0
|
44
38
|
type: :runtime
|
45
39
|
prerelease: false
|
46
40
|
version_requirements: !ruby/object:Gem::Requirement
|
47
41
|
requirements:
|
48
42
|
- - ">="
|
49
43
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
44
|
+
version: 3.1.1
|
51
45
|
- - "<"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 3.
|
47
|
+
version: 3.2.0
|
54
48
|
- !ruby/object:Gem::Dependency
|
55
49
|
name: uber
|
56
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,8 +151,8 @@ executables: []
|
|
157
151
|
extensions: []
|
158
152
|
extra_rdoc_files: []
|
159
153
|
files:
|
154
|
+
- ".github/workflows/ci.yml"
|
160
155
|
- ".gitignore"
|
161
|
-
- ".travis.yml"
|
162
156
|
- CHANGES.md
|
163
157
|
- CONTRIBUTING.md
|
164
158
|
- Gemfile
|
@@ -243,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
237
|
- !ruby/object:Gem::Version
|
244
238
|
version: '0'
|
245
239
|
requirements: []
|
246
|
-
rubygems_version: 3.
|
240
|
+
rubygems_version: 3.2.3
|
247
241
|
signing_key:
|
248
242
|
specification_version: 4
|
249
243
|
summary: Form object decoupled from models with validation, population and presentation.
|