formalism 0.4.0 → 0.5.1
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/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 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6602ff26f0ec729c7cb6fd37fa2c7b8897183c8f44437eb0ddebf24228e79592
|
4
|
+
data.tar.gz: e59eb7d592c7ecce60c9cb504f0bd2df8e30529f69b484105fa8153e6f906d8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e3792160e741752a5493a6bfdfba8bf32316816fa3633b7bc1f6ae2a26c3bcba84ff7384248c7caf3bab91435c9727962853c4b233ba7afc38d9da7155064e
|
7
|
+
data.tar.gz: 62080409f97ec8d5f713f621f35264f5697e6f4acae2e8ac192ece91d386a52e23e355ed75e557820de2c0529c9f5c63ed467f0fae6cca5dcac6d200144cebe4
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 0.5.1 (2022-09-24)
|
6
|
+
|
7
|
+
* Allow `gorilla_patch` version 5.
|
8
|
+
|
9
|
+
## 0.5.0 (2022-09-24)
|
10
|
+
|
11
|
+
* Drop Ruby 2.5 support.
|
12
|
+
* Add Ruby 3.1 support.
|
13
|
+
* Add coercion to `Object`.
|
14
|
+
* Add coercion to `Class`.
|
15
|
+
* Update development dependencies.
|
16
|
+
* Resolve new offenses from RuboCop.
|
17
|
+
* Resolve Ruby warnings.
|
18
|
+
* Increase tests coverage to 100%.
|
19
|
+
* Add `bundle-audit` CI task.
|
20
|
+
* Update metadata in gemspec.
|
4
21
|
|
5
22
|
## 0.4.0 (2021-02-11)
|
6
23
|
|
24
|
+
* Support Ruby 3.
|
25
|
+
* Update development dependencies.
|
26
|
+
* Resolve new RuboCop offenses.
|
27
|
+
|
7
28
|
## 0.3.1 (2020-10-02)
|
8
29
|
|
9
30
|
* Fix `Float` coercion to `BigDecimal`.
|
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,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formalism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gorilla_patch
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: module_methods
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,47 +73,47 @@ dependencies:
|
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '2.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: bundler-audit
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
79
|
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
81
|
+
version: 0.9.0
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
86
|
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
88
|
+
version: 0.9.0
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: gem_toys
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
95
|
+
version: 0.12.1
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
102
|
+
version: 0.12.1
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
104
|
+
name: toys
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
109
|
+
version: 0.13.0
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
116
|
+
version: 0.13.0
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: rspec
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,20 +142,34 @@ dependencies:
|
|
136
142
|
- - "~>"
|
137
143
|
- !ruby/object:Gem::Version
|
138
144
|
version: 0.21.2
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: simplecov-cobertura
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '2.1'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '2.1'
|
139
159
|
- !ruby/object:Gem::Dependency
|
140
160
|
name: rubocop
|
141
161
|
requirement: !ruby/object:Gem::Requirement
|
142
162
|
requirements:
|
143
163
|
- - "~>"
|
144
164
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
165
|
+
version: 1.36.0
|
146
166
|
type: :development
|
147
167
|
prerelease: false
|
148
168
|
version_requirements: !ruby/object:Gem::Requirement
|
149
169
|
requirements:
|
150
170
|
- - "~>"
|
151
171
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
172
|
+
version: 1.36.0
|
153
173
|
- !ruby/object:Gem::Dependency
|
154
174
|
name: rubocop-performance
|
155
175
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,10 +218,12 @@ files:
|
|
198
218
|
- lib/formalism/form/coercion/array.rb
|
199
219
|
- lib/formalism/form/coercion/bigdecimal.rb
|
200
220
|
- lib/formalism/form/coercion/boolean.rb
|
221
|
+
- lib/formalism/form/coercion/class.rb
|
201
222
|
- lib/formalism/form/coercion/date.rb
|
202
223
|
- lib/formalism/form/coercion/float.rb
|
203
224
|
- lib/formalism/form/coercion/hash.rb
|
204
225
|
- lib/formalism/form/coercion/integer.rb
|
226
|
+
- lib/formalism/form/coercion/object.rb
|
205
227
|
- lib/formalism/form/coercion/string.rb
|
206
228
|
- lib/formalism/form/coercion/symbol.rb
|
207
229
|
- lib/formalism/form/coercion/time.rb
|
@@ -214,9 +236,13 @@ homepage: https://github.com/AlexWayfer/formalism
|
|
214
236
|
licenses:
|
215
237
|
- MIT
|
216
238
|
metadata:
|
217
|
-
|
239
|
+
bug_tracker_uri: https://github.com/AlexWayfer/formalism/issues
|
240
|
+
changelog_uri: https://github.com/AlexWayfer/formalism/blob/v0.5.1/CHANGELOG.md
|
241
|
+
documentation_uri: http://www.rubydoc.info/gems/formalism/0.5.1
|
218
242
|
homepage_uri: https://github.com/AlexWayfer/formalism
|
219
|
-
|
243
|
+
rubygems_mfa_required: 'true'
|
244
|
+
source_code_uri: https://github.com/AlexWayfer/formalism
|
245
|
+
wiki_uri: https://github.com/AlexWayfer/formalism/wiki
|
220
246
|
post_install_message:
|
221
247
|
rdoc_options: []
|
222
248
|
require_paths:
|
@@ -225,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
251
|
requirements:
|
226
252
|
- - ">="
|
227
253
|
- !ruby/object:Gem::Version
|
228
|
-
version: '2.
|
254
|
+
version: '2.6'
|
229
255
|
- - "<"
|
230
256
|
- !ruby/object:Gem::Version
|
231
257
|
version: '4'
|
@@ -235,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
261
|
- !ruby/object:Gem::Version
|
236
262
|
version: '0'
|
237
263
|
requirements: []
|
238
|
-
rubygems_version: 3.
|
264
|
+
rubygems_version: 3.3.7
|
239
265
|
signing_key:
|
240
266
|
specification_version: 4
|
241
267
|
summary: Forms with input data validations and nesting
|