reform 2.5.0 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0b6b3c1dbb48304ae8b36f5fbc12d9f7149edc61b40757017472b3eb01cf04f
4
- data.tar.gz: 689811ffa73a062d4e598d8a36b6258571350d1ce4c5c87c85db9707313dde04
3
+ metadata.gz: cfedf66ab0e882b38dc82f0be8021a0207d1a4b7de280870e645edd4f4d0bc91
4
+ data.tar.gz: 821a8d3b673d5878233e53818c5eb30a69a057b48168af6c6d7c5a6e31b916cb
5
5
  SHA512:
6
- metadata.gz: a797c79e164c4c1791661a97163d4e89b1b2e49ae4992e1c0a59eb427d98ddfdbdae96292f455f843acacc869b5053916afa7131018843c66f4d886e6872c372
7
- data.tar.gz: 82fe647e1ab34dcc24e85250d5876b88b84ea3a991cdfb163bf0dd616be701105ab1ca87065285bc0e32abe9f67ccdb3cda103c7f70143e49d0a8c3024baa75e
6
+ metadata.gz: b9d1a8eda9d73c08cb550440195670147986b50baa80ccf03149afebebd0cde33804b1c522227251e368385a688819fdb27865f9149ad09fa28a73caaabf1672
7
+ data.tar.gz: 8a27e5df8bfbd8609f28d0f51401ced2a240363154908610b371d4ee533879d77ece09e02cc2e65b95262052eb6a8ffd8140aa8c06d14273d0cc5d50a7880eb5
@@ -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,17 @@
1
+ ## 2.6.2
2
+
3
+ * Loosen `representable` dependency to `< 4`.
4
+
5
+ ## 2.6.1
6
+
7
+ * Loosen `disposable` dependency to `>= 0.5.0`.
8
+
9
+ ## 2.6.0
10
+
11
+ * Support ruby-3 by using `Representable::Option` to handle `keyword_arguments` forwarding :tada:
12
+ * Upgrade `representable` and `disposable` dependencies which uses `trailblazer-option` over `declarative-option`.
13
+ * Deprecate populator's callable signature which accepts `form` as a separate positional argument. Make all callable (proc, method, `Uber::Callable`) signatures identical.
14
+
1
15
  ## 2.5.0
2
16
  * fix memory leak with Dry validation (#525)
3
17
 
@@ -28,7 +28,7 @@ module Reform::Form::Dry
28
28
  class Group
29
29
  include InputHash
30
30
 
31
- def initialize(**options)
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 = Declarative::Option(user_proc, instance_exec: true, callable: Object) # we can now process Callable, procs, :symbol.
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
- @value.(form, options) # Declarative::Option call.
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
- @value.(form, options)
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
- Declarative::Option(block, instance_exec: true).(self, options)
16
+ ::Representable::Option(block).(exec_context: self, keyword_arguments: options)
17
17
  end
18
18
  end
19
19
 
@@ -4,15 +4,15 @@ module Reform::Form::Validate
4
4
  class AllBlank
5
5
  include Uber::Callable
6
6
 
7
- def call(form, options)
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 = options[:input].each_with_object({}) { |(k, v), hash|
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
- options[:binding][:nested].definitions.each do |definition|
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
@@ -1,3 +1,3 @@
1
1
  module Reform
2
- VERSION = "2.5.0".freeze
2
+ VERSION = "2.6.2".freeze
3
3
  end
data/reform.gemspec CHANGED
@@ -17,14 +17,13 @@ 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", ">= 0.4.2", "< 0.5.0"
21
- spec.add_dependency "representable", ">= 2.4.0", "< 3.1.0"
20
+ spec.add_dependency "disposable", ">= 0.5.0", "< 1.0.0"
21
+ spec.add_dependency "representable", ">= 3.1.1", "< 4"
22
22
  spec.add_dependency "uber", "< 0.2.0"
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "minitest"
26
26
  spec.add_development_dependency "minitest-line"
27
- spec.add_development_dependency "pry-byebug"
28
27
  spec.add_development_dependency "multi_json"
29
28
  spec.add_development_dependency "rake"
30
29
  end
@@ -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
@@ -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
data/test/test_helper.rb CHANGED
@@ -3,7 +3,6 @@ require "minitest/autorun"
3
3
  require "representable/debug"
4
4
  require "declarative/testing"
5
5
  require "pp"
6
- require "pry-byebug"
7
6
 
8
7
  require "reform/form/dry"
9
8
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reform
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  - Fran Worley
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-26 00:00:00.000000000 Z
12
+ date: 2022-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: disposable
@@ -17,40 +17,40 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.4.2
20
+ version: 0.5.0
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: 0.5.0
23
+ version: 1.0.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 0.4.2
30
+ version: 0.5.0
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0
33
+ version: 1.0.0
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: representable
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.4.0
40
+ version: 3.1.1
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: 3.1.0
43
+ version: '4'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 2.4.0
50
+ version: 3.1.1
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: 3.1.0
53
+ version: '4'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: uber
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -107,20 +107,6 @@ dependencies:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: pry-byebug
112
- requirement: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
117
- type: :development
118
- prerelease: false
119
- version_requirements: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
124
110
  - !ruby/object:Gem::Dependency
125
111
  name: multi_json
126
112
  requirement: !ruby/object:Gem::Requirement
@@ -157,8 +143,8 @@ executables: []
157
143
  extensions: []
158
144
  extra_rdoc_files: []
159
145
  files:
146
+ - ".github/workflows/ci.yml"
160
147
  - ".gitignore"
161
- - ".travis.yml"
162
148
  - CHANGES.md
163
149
  - CONTRIBUTING.md
164
150
  - Gemfile
@@ -228,7 +214,7 @@ homepage: https://github.com/trailblazer/reform
228
214
  licenses:
229
215
  - MIT
230
216
  metadata: {}
231
- post_install_message:
217
+ post_install_message:
232
218
  rdoc_options: []
233
219
  require_paths:
234
220
  - lib
@@ -243,8 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
229
  - !ruby/object:Gem::Version
244
230
  version: '0'
245
231
  requirements: []
246
- rubygems_version: 3.0.3
247
- signing_key:
232
+ rubygems_version: 3.3.7
233
+ signing_key:
248
234
  specification_version: 4
249
235
  summary: Form object decoupled from models with validation, population and presentation.
250
236
  test_files:
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- bundler_args: --without benchmarks tools
4
- rvm:
5
- - ruby-head
6
- - 2.7
7
- - 2.6
8
- - 2.5
9
- - 2.4
10
- matrix:
11
- fast_finish: true
12
- allow_failures:
13
- - rvm: ruby-head