formalism 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/README.md +3 -3
- data/lib/formalism/form/coercion/_base.rb +6 -5
- data/lib/formalism/form/coercion/boolean.rb +1 -1
- data/lib/formalism/form/coercion/class.rb +20 -0
- data/lib/formalism/form/coercion/object.rb +19 -0
- data/lib/formalism/form/fields.rb +2 -5
- data/lib/formalism/form/filling.rb +16 -9
- data/lib/formalism/version.rb +1 -1
- metadata +45 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad623280e245382a579b55f7668ce3a89d976ceaf6f0ba8f5346d42e03bf0c9f
|
4
|
+
data.tar.gz: b7f4ebbeb278e900f13b5de14e24365ace8f96df2b891d062a72d568fdfc3a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c84923d4879d339aa26142d966bc27f69328377e99c2aef2e51ca9f919a436b803702eb109437510ba930de8ad70c6179ad953e69816bc447a08ae13857d947
|
7
|
+
data.tar.gz: 59bdf6f1ec9997126fa14e49d74bc73259b0d3d0b062f84198909db5956130b092f875b48e7a6a0f8703e58b67e1a2a16abdb5dd33728718ff817539fb6e9bc6
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 0.5.0 (2022-09-24)
|
6
|
+
|
7
|
+
* Drop Ruby 2.5 support.
|
8
|
+
* Add Ruby 3.1 support.
|
9
|
+
* Add coercion to `Object`.
|
10
|
+
* Add coercion to `Class`.
|
11
|
+
* Update development dependencies.
|
12
|
+
* Resolve new offenses from RuboCop.
|
13
|
+
* Resolve Ruby warnings.
|
14
|
+
* Increase tests coverage to 100%.
|
15
|
+
* Add `bundle-audit` CI task.
|
16
|
+
* Update metadata in gemspec.
|
17
|
+
|
18
|
+
## 0.4.0 (2021-02-11)
|
19
|
+
|
20
|
+
* Support Ruby 3.
|
21
|
+
* Update development dependencies.
|
22
|
+
* Resolve new RuboCop offenses.
|
4
23
|
|
5
24
|
## 0.3.1 (2020-10-02)
|
6
25
|
|
26
|
+
* Fix `Float` coercion to `BigDecimal`.
|
27
|
+
|
7
28
|
## 0.3.0 (2020-09-28)
|
8
29
|
|
9
30
|
* Add `BigDecimal` coercion.
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Formalism
|
2
2
|
|
3
3
|
[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/formalism?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/formalism)
|
4
|
-
[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/formalism/
|
4
|
+
[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/formalism/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/formalism)
|
5
5
|
[![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/formalism.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/formalism)
|
6
6
|
[![Depfu](https://img.shields.io/depfu/AlexWayfer/benchmark_toys?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/formalism)
|
7
|
-
[![Inline docs](https://inch-ci.org/github/AlexWayfer/formalism.svg?branch=
|
8
|
-
[![license](https://img.shields.io/github/license/AlexWayfer/formalism.svg?style=flat-square)](https://github.com/AlexWayfer/formalism/blob/
|
7
|
+
[![Inline docs](https://inch-ci.org/github/AlexWayfer/formalism.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/formalism)
|
8
|
+
[![license](https://img.shields.io/github/license/AlexWayfer/formalism.svg?style=flat-square)](https://github.com/AlexWayfer/formalism/blob/main/LICENSE.txt)
|
9
9
|
[![Gem](https://img.shields.io/gem/v/formalism.svg?style=flat-square)](https://rubygems.org/gems/formalism)
|
10
10
|
|
11
11
|
Ruby gem for forms with validations and nesting.
|
@@ -8,12 +8,13 @@ module Formalism
|
|
8
8
|
def initialize(value, *)
|
9
9
|
@value = value
|
10
10
|
|
11
|
-
type_name = self.class.name.split('::')[3
|
11
|
+
type_name = self.class.name.split('::')[3..].join('::')
|
12
12
|
|
13
13
|
@type =
|
14
|
-
if Object.const_defined?(type_name, false)
|
15
|
-
|
16
|
-
else
|
14
|
+
if ::Object.const_defined?(type_name, false)
|
15
|
+
::Object.const_get(type_name, false)
|
16
|
+
else
|
17
|
+
type_name
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -26,7 +27,7 @@ module Formalism
|
|
26
27
|
private
|
27
28
|
|
28
29
|
def should_be_coreced?
|
29
|
-
@type != 'Base' && !(@type.is_a?(Class) && @value.is_a?(@type))
|
30
|
+
@type != 'Base' && !(@type.is_a?(::Class) && @value.is_a?(@type))
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Formalism
|
4
|
+
class Form < Action
|
5
|
+
class Coercion
|
6
|
+
## Class for coercion to Class
|
7
|
+
class Class < Base
|
8
|
+
private
|
9
|
+
|
10
|
+
def execute
|
11
|
+
return @value if @value.is_a? Class
|
12
|
+
|
13
|
+
return if @value.to_s.empty?
|
14
|
+
|
15
|
+
::Object.const_get(@value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Formalism
|
4
|
+
class Form < Action
|
5
|
+
class Coercion
|
6
|
+
## Class for coercion to Object (formally everything is Object)
|
7
|
+
class Object < Base
|
8
|
+
private
|
9
|
+
|
10
|
+
def execute
|
11
|
+
## There are other `is_a?` checks, fuck it
|
12
|
+
# return unless @value.respond_to? :is_a? ## BasicObject
|
13
|
+
|
14
|
+
@value if @value.is_a? ::Object
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -38,8 +38,7 @@ module Formalism
|
|
38
38
|
|
39
39
|
def nested(name, form = nil, **options)
|
40
40
|
unless form || options.key?(:initialize)
|
41
|
-
raise ArgumentError, 'Neither form class nor initialize block '
|
42
|
-
'is not present'
|
41
|
+
raise ArgumentError, 'Neither form class nor initialize block is not present'
|
43
42
|
end
|
44
43
|
|
45
44
|
fields_and_nested_forms[name] = options.merge(form: form)
|
@@ -132,9 +131,7 @@ module Formalism
|
|
132
131
|
for_merge ? select_for_merge(:nested_forms) : nested_forms
|
133
132
|
|
134
133
|
fields(for_merge: for_merge).merge(
|
135
|
-
merging_nested_forms
|
136
|
-
.map { |name, _nested_form| [name, public_send(name)] }
|
137
|
-
.to_h
|
134
|
+
merging_nested_forms.to_h { |name, _nested_form| [name, public_send(name)] }
|
138
135
|
)
|
139
136
|
end
|
140
137
|
|
@@ -52,7 +52,9 @@ module Formalism
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def fill_nested_form(name, options)
|
55
|
-
|
55
|
+
args = args_for_nested_form(name, options)
|
56
|
+
|
57
|
+
return unless (form = initialize_nested_form(options, args))
|
56
58
|
|
57
59
|
nested_forms[name] = form
|
58
60
|
end
|
@@ -61,19 +63,24 @@ module Formalism
|
|
61
63
|
default.is_a?(Proc) ? instance_exec(&default) : default
|
62
64
|
end
|
63
65
|
|
64
|
-
def initialize_nested_form(
|
65
|
-
args =
|
66
|
-
if @params.key?(name) then [send("params_for_nested_#{name}")]
|
67
|
-
elsif instance_respond_to?(name) then [instance_public_send(name)]
|
68
|
-
elsif options.key?(:default) then [process_default(options[:default])]
|
69
|
-
else []
|
70
|
-
end
|
71
|
-
|
66
|
+
def initialize_nested_form(options, args)
|
72
67
|
result =
|
73
68
|
instance_exec options[:form], &options.fetch(:initialize, ->(form) { form.new(*args) })
|
74
69
|
result.runnable = false unless runnable
|
75
70
|
result
|
76
71
|
end
|
72
|
+
|
73
|
+
def args_for_nested_form(name, options)
|
74
|
+
if @params.key?(name)
|
75
|
+
[send("params_for_nested_#{name}")]
|
76
|
+
elsif instance_respond_to?(name)
|
77
|
+
[instance_public_send(name)]
|
78
|
+
elsif options.key?(:default)
|
79
|
+
[process_default(options[:default])]
|
80
|
+
else
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
end
|
77
84
|
end
|
78
85
|
|
79
86
|
private_constant :Filling
|
data/lib/formalism/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formalism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gorilla_patch
|
@@ -67,47 +67,47 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bundler-audit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.9.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.9.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: gem_toys
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.12.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.12.1
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: toys
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.13.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.13.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,28 +128,42 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.21.2
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
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'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rubocop
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
159
|
+
version: 1.36.0
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
166
|
+
version: 1.36.0
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: rubocop-performance
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +184,14 @@ dependencies:
|
|
170
184
|
requirements:
|
171
185
|
- - "~>"
|
172
186
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
187
|
+
version: '2.0'
|
174
188
|
type: :development
|
175
189
|
prerelease: false
|
176
190
|
version_requirements: !ruby/object:Gem::Requirement
|
177
191
|
requirements:
|
178
192
|
- - "~>"
|
179
193
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
194
|
+
version: '2.0'
|
181
195
|
description: 'Simple actions and complex forms with validations, nesting, etc.
|
182
196
|
|
183
197
|
'
|
@@ -198,10 +212,12 @@ files:
|
|
198
212
|
- lib/formalism/form/coercion/array.rb
|
199
213
|
- lib/formalism/form/coercion/bigdecimal.rb
|
200
214
|
- lib/formalism/form/coercion/boolean.rb
|
215
|
+
- lib/formalism/form/coercion/class.rb
|
201
216
|
- lib/formalism/form/coercion/date.rb
|
202
217
|
- lib/formalism/form/coercion/float.rb
|
203
218
|
- lib/formalism/form/coercion/hash.rb
|
204
219
|
- lib/formalism/form/coercion/integer.rb
|
220
|
+
- lib/formalism/form/coercion/object.rb
|
205
221
|
- lib/formalism/form/coercion/string.rb
|
206
222
|
- lib/formalism/form/coercion/symbol.rb
|
207
223
|
- lib/formalism/form/coercion/time.rb
|
@@ -214,25 +230,32 @@ homepage: https://github.com/AlexWayfer/formalism
|
|
214
230
|
licenses:
|
215
231
|
- MIT
|
216
232
|
metadata:
|
217
|
-
|
233
|
+
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
|
218
236
|
homepage_uri: https://github.com/AlexWayfer/formalism
|
219
|
-
|
237
|
+
rubygems_mfa_required: 'true'
|
238
|
+
source_code_uri: https://github.com/AlexWayfer/formalism
|
239
|
+
wiki_uri: https://github.com/AlexWayfer/formalism/wiki
|
220
240
|
post_install_message:
|
221
241
|
rdoc_options: []
|
222
242
|
require_paths:
|
223
243
|
- lib
|
224
244
|
required_ruby_version: !ruby/object:Gem::Requirement
|
225
245
|
requirements:
|
226
|
-
- - "
|
246
|
+
- - ">="
|
247
|
+
- !ruby/object:Gem::Version
|
248
|
+
version: '2.6'
|
249
|
+
- - "<"
|
227
250
|
- !ruby/object:Gem::Version
|
228
|
-
version: '
|
251
|
+
version: '4'
|
229
252
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
253
|
requirements:
|
231
254
|
- - ">="
|
232
255
|
- !ruby/object:Gem::Version
|
233
256
|
version: '0'
|
234
257
|
requirements: []
|
235
|
-
rubygems_version: 3.
|
258
|
+
rubygems_version: 3.3.7
|
236
259
|
signing_key:
|
237
260
|
specification_version: 4
|
238
261
|
summary: Forms with input data validations and nesting
|