formalism 0.4.0 → 0.5.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: d720c9642bb31c7c706c3945de0f043c6dcb593d5e509afe137b396d38b2c9a1
4
- data.tar.gz: 8b98535c509f4c4845542203a92e6093141c32f76f6ffc1da4b092ba668f5cb3
3
+ metadata.gz: ad623280e245382a579b55f7668ce3a89d976ceaf6f0ba8f5346d42e03bf0c9f
4
+ data.tar.gz: b7f4ebbeb278e900f13b5de14e24365ace8f96df2b891d062a72d568fdfc3a56
5
5
  SHA512:
6
- metadata.gz: 99427b0a3845b7be7d09a18ffc5c450613433ce19fa103e8e1cb3134cd795011e24f346145ebac5666f0f9b26cebfc85e43ac479fc8c6ef82b28e12e88483802
7
- data.tar.gz: a072477df6a7850b2309f14431b933ced7ddac1eeeef9c1aab27277e206182984cb792ad721a0c2e6d2aa2451b676d5771462288491dc4fad48b956605b96ac4
6
+ metadata.gz: 6c84923d4879d339aa26142d966bc27f69328377e99c2aef2e51ca9f919a436b803702eb109437510ba930de8ad70c6179ad953e69816bc447a08ae13857d947
7
+ data.tar.gz: 59bdf6f1ec9997126fa14e49d74bc73259b0d3d0b062f84198909db5956130b092f875b48e7a6a0f8703e58b67e1a2a16abdb5dd33728718ff817539fb6e9bc6
data/CHANGELOG.md CHANGED
@@ -1,9 +1,26 @@
1
1
  # Changelog
2
2
 
3
- ## master (unreleased)
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.
4
17
 
5
18
  ## 0.4.0 (2021-02-11)
6
19
 
20
+ * Support Ruby 3.
21
+ * Update development dependencies.
22
+ * Resolve new RuboCop offenses.
23
+
7
24
  ## 0.3.1 (2020-10-02)
8
25
 
9
26
  * 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/master.svg?style=flat-square)](https://codecov.io/gh/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=master)](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/master/LICENSE.txt)
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..-1].join('::')
11
+ type_name = self.class.name.split('::')[3..].join('::')
12
12
 
13
13
  @type =
14
- if Object.const_defined?(type_name, false)
15
- then Object.const_get(type_name, false)
16
- else type_name
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
- return unless (form = initialize_nested_form(name, options))
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(name, options)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Formalism
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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.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: 2021-02-10 00:00:00.000000000 Z
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: gem_toys
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.6.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.6.0
82
+ version: 0.9.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: toys
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.11.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.11.0
96
+ version: 0.12.1
97
97
  - !ruby/object:Gem::Dependency
98
- name: codecov
98
+ name: toys
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.4.2
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.4.2
110
+ version: 0.13.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
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: '1.4'
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: '1.4'
166
+ version: 1.36.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-performance
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -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,9 +230,13 @@ homepage: https://github.com/AlexWayfer/formalism
214
230
  licenses:
215
231
  - MIT
216
232
  metadata:
217
- source_code_uri: https://github.com/AlexWayfer/formalism
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
- changelog_uri: https://github.com/AlexWayfer/formalism/blob/master/CHANGELOG.md
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:
@@ -225,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
245
  requirements:
226
246
  - - ">="
227
247
  - !ruby/object:Gem::Version
228
- version: '2.5'
248
+ version: '2.6'
229
249
  - - "<"
230
250
  - !ruby/object:Gem::Version
231
251
  version: '4'
@@ -235,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
255
  - !ruby/object:Gem::Version
236
256
  version: '0'
237
257
  requirements: []
238
- rubygems_version: 3.2.3
258
+ rubygems_version: 3.3.7
239
259
  signing_key:
240
260
  specification_version: 4
241
261
  summary: Forms with input data validations and nesting