formalism 0.5.0 → 0.6.0

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: ad623280e245382a579b55f7668ce3a89d976ceaf6f0ba8f5346d42e03bf0c9f
4
- data.tar.gz: b7f4ebbeb278e900f13b5de14e24365ace8f96df2b891d062a72d568fdfc3a56
3
+ metadata.gz: 8e4d832e0f29d4c483ca8abde0e9cda368ecc7780ab3486bbff2d2436acf3683
4
+ data.tar.gz: e3d4f0eca76bffa706c658644d4e612d3a11122a933c203b39b418bac1bae2ca
5
5
  SHA512:
6
- metadata.gz: 6c84923d4879d339aa26142d966bc27f69328377e99c2aef2e51ca9f919a436b803702eb109437510ba930de8ad70c6179ad953e69816bc447a08ae13857d947
7
- data.tar.gz: 59bdf6f1ec9997126fa14e49d74bc73259b0d3d0b062f84198909db5956130b092f875b48e7a6a0f8703e58b67e1a2a16abdb5dd33728718ff817539fb6e9bc6
6
+ metadata.gz: 5cc302ffffc7acb362dab453f56cf96bd669845b8f8cf74acfd0e8c268cb76f5599872a039e62430dc4945500b74570ce35963808a7ae48d057eeb5f9643984f
7
+ data.tar.gz: 016edfd06e2f810efac6a14325d75ea4c81ccae1bbcac93cf6cdd2c8c98555e9ea4ab3053c8948168b1770b5afbc96ce064e2f56764ce7ecac43d76edebeaa70
data/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.6.0 (2025-01-06)
6
+
7
+ * Drop Ruby 2.6 and 2.7 support.
8
+ * Add Ruby 3.2, 3.3 and 3.4 support.
9
+ * Lock Ruby version more strict.
10
+ There can be breaking changes in minor updates.
11
+ * Improve documentation.
12
+ * Update development dependencies.
13
+ * Resolve new offenses from RuboCop.
14
+ * Move development dependencies from `gemspec` into `Gemfile`.
15
+
16
+ ## 0.5.1 (2022-09-24)
17
+
18
+ * Allow `gorilla_patch` version 5.
19
+
5
20
  ## 0.5.0 (2022-09-24)
6
21
 
7
22
  * Drop Ruby 2.5 support.
data/README.md CHANGED
@@ -289,6 +289,22 @@ form.to_params
289
289
  For actions without fields, nesting and validation you can use
290
290
  `Formalism::Action` (the parent of `Formalism::Form`).
291
291
 
292
+
293
+ ### Plugins
294
+
295
+ There is a few plugins which I personally need for:
296
+
297
+ * [`formalism-model_forms`](https://github.com/AlexWayfer/formalism-model_forms)
298
+ Default CRUD forms for [Sequel](https://sequel.jeremyevans.net/) DB models.
299
+ Can be renamed!
300
+
301
+ * [`formalism-sequel_transactions`](https://github.com/AlexWayfer/formalism-sequel_transactions)
302
+ [Sequel](https://sequel.jeremyevans.net/) transactions inside forms.
303
+
304
+ * [`formalism-r18n_errors`](https://github.com/AlexWayfer/formalism-r18n_errors)
305
+ [R18n](https://github.com/r18n/r18n) errors inside forms, including validation helpers.
306
+ Can be separated!
307
+
292
308
  ## Development
293
309
 
294
310
  After checking out the repo, run `bundle install` to install dependencies.
@@ -9,7 +9,7 @@ module Formalism
9
9
  private
10
10
 
11
11
  def wrap_value_regexp(content)
12
- /\A\s*#{content}\s*\z/.freeze
12
+ /\A\s*#{content}\s*\z/
13
13
  end
14
14
  end
15
15
 
@@ -53,7 +53,7 @@ module Formalism
53
53
  ## Error for undefined type in coercion
54
54
  class NoCoercionError < ArgumentError
55
55
  def initialize(type)
56
- super "Formalism has no coercion to #{type}"
56
+ super("Formalism has no coercion to #{type}")
57
57
  end
58
58
  end
59
59
  end
@@ -52,7 +52,7 @@ module Formalism
52
52
  fields_and_nested_forms.delete name
53
53
 
54
54
  undef_method name
55
- undef_method "#{name}="
55
+ undef_method :"#{name}="
56
56
  end
57
57
 
58
58
  def define_field_methods(name)
@@ -61,18 +61,31 @@ module Formalism
61
61
 
62
62
  private
63
63
 
64
- define_method("#{name}=") do |value|
64
+ define_method :"#{name}=" do |value|
65
65
  options = self.class.fields_and_nested_forms[name]
66
- coerced_value =
67
- Coercion.new(*options.values_at(:type, :of)).result_for(value)
66
+ coerced_value = Coercion.new(*options.values_at(:type, :of)).result_for(value)
68
67
  fields[name] = coerced_value
69
68
  end
70
69
  end
70
+
71
+ reset_undefined_field_methods(name)
72
+ end
73
+
74
+ def reset_undefined_field_methods(name)
75
+ class_exec do
76
+ define_method(name) { super() }
77
+ remove_method name
78
+
79
+ private
80
+
81
+ define_method(:"#{name}=") { |value| super(value) }
82
+ remove_method :"#{name}="
83
+ end
71
84
  end
72
85
 
73
86
  def define_nested_form_methods(name)
74
87
  module_for_accessors.instance_exec do
75
- define_method("#{name}_form") { nested_forms[name] }
88
+ define_method(:"#{name}_form") { nested_forms[name] }
76
89
 
77
90
  define_method(name) { nested_forms[name].instance }
78
91
  end
@@ -83,13 +96,14 @@ module Formalism
83
96
  def define_params_for_nested_method(name)
84
97
  params_method_name = "params_for_nested_#{name}"
85
98
  params_method_defined =
86
- method_defined?(params_method_name) ||
87
- private_method_defined?(params_method_name)
99
+ method_defined?(params_method_name) || private_method_defined?(params_method_name)
100
+
101
+ return if params_method_defined
88
102
 
89
103
  module_for_accessors.instance_exec do
90
104
  private
91
105
 
92
- define_method(params_method_name) { @params[name] } unless params_method_defined
106
+ define_method(params_method_name) { @params[name] }
93
107
  end
94
108
  end
95
109
 
@@ -72,7 +72,7 @@ module Formalism
72
72
 
73
73
  def args_for_nested_form(name, options)
74
74
  if @params.key?(name)
75
- [send("params_for_nested_#{name}")]
75
+ [send(:"params_for_nested_#{name}")]
76
76
  elsif instance_respond_to?(name)
77
77
  [instance_public_send(name)]
78
78
  elsif options.key?(:default)
@@ -8,7 +8,7 @@ module Formalism
8
8
 
9
9
  def initialize(errors)
10
10
  @errors = errors
11
- super "Outcome has errors: #{errors.to_a}"
11
+ super("Outcome has errors: #{errors.to_a}")
12
12
  end
13
13
  end
14
14
  end
@@ -32,7 +32,10 @@ module Formalism
32
32
  end
33
33
 
34
34
  def valid?
35
+ ## https://github.com/rubocop/rubocop/pull/11967#issuecomment-1605561645
36
+ # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
35
37
  return unless runnable
38
+ # rubocop:enable Style/ReturnNilInPredicateMethodDefinition
36
39
 
37
40
  errors.clear
38
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Formalism
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,29 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formalism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
10
+ date: 2025-01-06 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: gorilla_patch
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '4'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '6'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
28
  version: '4'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '6'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: module_methods
29
34
  requirement: !ruby/object:Gem::Requirement
@@ -38,160 +43,6 @@ dependencies:
38
43
  - - "~>"
39
44
  - !ruby/object:Gem::Version
40
45
  version: 0.1.0
41
- - !ruby/object:Gem::Dependency
42
- name: pry-byebug
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.9'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.9'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
- - !ruby/object:Gem::Dependency
70
- name: bundler-audit
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.9.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.9.0
83
- - !ruby/object:Gem::Dependency
84
- name: gem_toys
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.12.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.12.1
97
- - !ruby/object:Gem::Dependency
98
- name: toys
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 0.13.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 0.13.0
111
- - !ruby/object:Gem::Dependency
112
- name: rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '3.9'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '3.9'
125
- - !ruby/object:Gem::Dependency
126
- name: simplecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.21.2
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.21.2
139
- - !ruby/object:Gem::Dependency
140
- name: simplecov-cobertura
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '2.1'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '2.1'
153
- - !ruby/object:Gem::Dependency
154
- name: rubocop
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 1.36.0
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 1.36.0
167
- - !ruby/object:Gem::Dependency
168
- name: rubocop-performance
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '1.0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '1.0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop-rspec
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '2.0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '2.0'
195
46
  description: 'Simple actions and complex forms with validations, nesting, etc.
196
47
 
197
48
  '
@@ -231,13 +82,12 @@ licenses:
231
82
  - MIT
232
83
  metadata:
233
84
  bug_tracker_uri: https://github.com/AlexWayfer/formalism/issues
234
- changelog_uri: https://github.com/AlexWayfer/formalism/blob/v0.5.0/CHANGELOG.md
235
- documentation_uri: http://www.rubydoc.info/gems/formalism/0.5.0
85
+ changelog_uri: https://github.com/AlexWayfer/formalism/blob/v0.6.0/CHANGELOG.md
86
+ documentation_uri: http://www.rubydoc.info/gems/formalism/0.6.0
236
87
  homepage_uri: https://github.com/AlexWayfer/formalism
237
88
  rubygems_mfa_required: 'true'
238
89
  source_code_uri: https://github.com/AlexWayfer/formalism
239
90
  wiki_uri: https://github.com/AlexWayfer/formalism/wiki
240
- post_install_message:
241
91
  rdoc_options: []
242
92
  require_paths:
243
93
  - lib
@@ -245,18 +95,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
95
  requirements:
246
96
  - - ">="
247
97
  - !ruby/object:Gem::Version
248
- version: '2.6'
98
+ version: '3.0'
249
99
  - - "<"
250
100
  - !ruby/object:Gem::Version
251
- version: '4'
101
+ version: '3.5'
252
102
  required_rubygems_version: !ruby/object:Gem::Requirement
253
103
  requirements:
254
104
  - - ">="
255
105
  - !ruby/object:Gem::Version
256
106
  version: '0'
257
107
  requirements: []
258
- rubygems_version: 3.3.7
259
- signing_key:
108
+ rubygems_version: 3.6.2
260
109
  specification_version: 4
261
110
  summary: Forms with input data validations and nesting
262
111
  test_files: []