formalism-model_forms 0.6.1 → 0.8.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 -0
- data/lib/formalism/model_forms.rb +4 -1
- data/lib/formalism/model_forms/_base.rb +28 -3
- data/lib/formalism/model_forms/delete.rb +4 -2
- data/lib/formalism/model_forms/find.rb +1 -1
- data/lib/formalism/model_forms/find_or_create.rb +12 -3
- data/lib/formalism/model_forms/list.rb +4 -2
- data/lib/formalism/model_forms/move.rb +3 -3
- data/lib/formalism/model_forms/select.rb +1 -1
- data/lib/formalism/model_forms/update.rb +5 -5
- data/lib/formalism/model_forms/version.rb +1 -1
- metadata +19 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb6265733b776ca5782e1aba24dddc3c970757a89d9bb98471d98a920aa9a505
|
4
|
+
data.tar.gz: c043043ca1857d578e7640048cd506bd4f8c6ed20e2105f8f0372e9f0a1d4b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5328cd192ef3378b687bb82a17aaa65665bbf021b10903ec232d032943e81068a9686695fc2976bd42301d2db48b4c75bf8f3e6e3c8e587528a8ba07574b1ac
|
7
|
+
data.tar.gz: 5e06bbf7f096280a8b73ef6bd346529656c60d295082b49e5e9dc354b434e4b96c31c141afdcc7b8fef440a14efbb9dca804a1ec7dd221b364fee745124cae78
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,30 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.8.0 (2021-02-11)
|
6
|
+
|
7
|
+
## 0.7.2 (2020-11-11)
|
8
|
+
|
9
|
+
* Fix error with `primary_field`.
|
10
|
+
* Fix an error when project has no models (and namespace) yet.
|
11
|
+
* Update development dependencies.
|
12
|
+
|
13
|
+
## 0.7.1 (2020-10-15)
|
14
|
+
|
15
|
+
* Fix `Delete` form for models without `auditable` plugin.
|
16
|
+
|
17
|
+
## 0.7.0 (2020-10-14)
|
18
|
+
|
19
|
+
* Add `primary_field`, don't lock on `id` field.
|
20
|
+
|
21
|
+
## 0.6.2 (2020-09-28)
|
22
|
+
|
23
|
+
* Update `formalism` to a new version.
|
24
|
+
|
5
25
|
## 0.6.1 (2020-09-28)
|
6
26
|
|
27
|
+
* Fix case when there is instance and `nil` params for `Update` form.
|
28
|
+
|
7
29
|
## 0.6.0 (2020-09-23)
|
8
30
|
|
9
31
|
* Fix complex error with `name` of anonymous classes and `inherited`.
|
@@ -43,11 +43,14 @@ module Formalism
|
|
43
43
|
FORM_CLASSES.each do |form_name, parent_name|
|
44
44
|
forms_namespace::Model.class_eval(
|
45
45
|
<<~CODE,
|
46
|
+
# class Update < FB::Forms::Model::Base
|
47
|
+
# include ModelForms::Update
|
48
|
+
# end
|
46
49
|
class #{form_name} < #{forms_namespace}::Model::#{parent_name}
|
47
50
|
include ModelForms::#{form_name}
|
48
51
|
end
|
49
52
|
CODE
|
50
|
-
__FILE__, __LINE__ -
|
53
|
+
__FILE__, __LINE__ - 7
|
51
54
|
)
|
52
55
|
end
|
53
56
|
end
|
@@ -17,7 +17,7 @@ module Formalism
|
|
17
17
|
extend Forwardable
|
18
18
|
def_delegators(
|
19
19
|
'self.class',
|
20
|
-
:namespace, :model_name, :model, :instance_variable_name
|
20
|
+
:primary_field_name, :namespace, :model_name, :model, :instance_variable_name
|
21
21
|
)
|
22
22
|
|
23
23
|
## Module for Base form class methods
|
@@ -27,6 +27,8 @@ module Formalism
|
|
27
27
|
def inherited(form)
|
28
28
|
super
|
29
29
|
|
30
|
+
form.primary_field_name = primary_field_name
|
31
|
+
|
30
32
|
return if form.instance_name == :model
|
31
33
|
return if form.method_defined?(form.instance_name.to_s)
|
32
34
|
|
@@ -34,6 +36,27 @@ module Formalism
|
|
34
36
|
form.alias_method "#{form.instance_name}=", :instance=
|
35
37
|
end
|
36
38
|
|
39
|
+
def included(something)
|
40
|
+
super
|
41
|
+
something.primary_field_name = primary_field_name
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_accessor :primary_field_name
|
45
|
+
|
46
|
+
def primary_field(name, *args, **kwargs)
|
47
|
+
remove_field primary_field_name if primary_field_name
|
48
|
+
|
49
|
+
field name, *args, **kwargs
|
50
|
+
|
51
|
+
self.primary_field_name = name
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_field(name)
|
55
|
+
super
|
56
|
+
|
57
|
+
self.primary_field_name = nil if name == primary_field_name
|
58
|
+
end
|
59
|
+
|
37
60
|
using GorillaPatch::Namespace
|
38
61
|
using GorillaPatch::Inflections
|
39
62
|
|
@@ -43,7 +66,7 @@ module Formalism
|
|
43
66
|
|
44
67
|
memoize def model_name
|
45
68
|
deconstantize.split('::')[2..-1].reverse
|
46
|
-
.find { |part| self::MODELS_NAMESPACE
|
69
|
+
.find { |part| self::MODELS_NAMESPACE&.const_defined?(part, false) || part == 'Model' }
|
47
70
|
end
|
48
71
|
|
49
72
|
memoize def model
|
@@ -93,7 +116,9 @@ module Formalism
|
|
93
116
|
attr_writer :instance
|
94
117
|
|
95
118
|
def find_instance
|
96
|
-
model
|
119
|
+
model
|
120
|
+
.first(primary_field_name => public_send(primary_field_name))
|
121
|
+
.public_send(@cached ? :dup : :itself)
|
97
122
|
end
|
98
123
|
|
99
124
|
def field_condition(name, value)
|
@@ -16,12 +16,14 @@ module Formalism
|
|
16
16
|
# end
|
17
17
|
# end
|
18
18
|
|
19
|
-
|
19
|
+
primary_field :id, Integer
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def execute
|
24
|
-
|
24
|
+
if model.respond_to?(:auditable?) && model.auditable?
|
25
|
+
instance.changes_author = changes_author
|
26
|
+
end
|
25
27
|
|
26
28
|
instance.destroy
|
27
29
|
super
|
@@ -11,11 +11,20 @@ module Formalism
|
|
11
11
|
def inherited(child_form)
|
12
12
|
super
|
13
13
|
|
14
|
-
|
14
|
+
child_form_path = File.dirname caller_locations(1..1).first.path
|
15
|
+
%w[find create].each { |form_type| require "#{child_form_path}/#{form_type}" }
|
16
|
+
|
17
|
+
child_form.define_nested_forms
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def define_nested_forms
|
23
|
+
nested :find, namespace::Find,
|
15
24
|
initialize: ->(form) { form.new(@params_or_instance) },
|
16
|
-
|
25
|
+
merge_errors: false
|
17
26
|
|
18
|
-
|
27
|
+
nested :create, namespace::Create,
|
19
28
|
initialize: ->(form) { form.new(@params_or_instance) },
|
20
29
|
errors_key: nil,
|
21
30
|
merge_errors: -> { find_form.instance.nil? }
|
@@ -78,7 +78,7 @@ module Formalism
|
|
78
78
|
|
79
79
|
def ordered_unfiltered_dataset
|
80
80
|
result = unfiltered_dataset.from_self(alias: model.table_name)
|
81
|
-
result = result.reverse_order(:
|
81
|
+
result = result.reverse_order(:created_at) unless unfiltered_dataset.opts[:order]
|
82
82
|
result
|
83
83
|
end
|
84
84
|
|
@@ -87,7 +87,9 @@ module Formalism
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def non_cached_dataset_for_execute
|
90
|
-
dataset.where(
|
90
|
+
dataset.where(
|
91
|
+
primary_field_name => dataset.select(primary_field_name).limit(limit_by_page)
|
92
|
+
)
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
@@ -6,15 +6,15 @@ module Formalism
|
|
6
6
|
module Move
|
7
7
|
include Formalism::ModelForms::Base
|
8
8
|
|
9
|
-
|
9
|
+
primary_field :id, Integer
|
10
10
|
|
11
11
|
attr_reader :direction
|
12
12
|
|
13
|
-
def initialize(direction,
|
13
|
+
def initialize(direction, primary_field_value, how_many = 1)
|
14
14
|
@direction = direction.to_sym
|
15
15
|
@how_many = how_many.to_i
|
16
16
|
|
17
|
-
super(
|
17
|
+
super(primary_field_name => primary_field_value)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -7,7 +7,7 @@ module Formalism
|
|
7
7
|
include Formalism::ModelForms::Base
|
8
8
|
extend ModelForms::Base::Plural
|
9
9
|
|
10
|
-
|
10
|
+
primary_field :id, Array, of: Integer, default: []
|
11
11
|
|
12
12
|
def initialize(params_or_instance = {})
|
13
13
|
## Instance should be an `Array` if there is not `params`
|
@@ -21,13 +21,13 @@ module Formalism
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
primary_field :id, Integer, merge: false
|
25
25
|
|
26
|
-
def initialize(params,
|
27
|
-
if
|
28
|
-
self.instance =
|
26
|
+
def initialize(params, pf_or_instance)
|
27
|
+
if pf_or_instance.is_a?(model)
|
28
|
+
self.instance = pf_or_instance
|
29
29
|
else
|
30
|
-
|
30
|
+
public_send "#{primary_field_name}=", pf_or_instance
|
31
31
|
end
|
32
32
|
|
33
33
|
super params || {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formalism-model_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alt_memery
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 0.4.0
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.4.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: gorilla_patch
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,14 +129,14 @@ dependencies:
|
|
129
129
|
requirements:
|
130
130
|
- - "~>"
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.
|
132
|
+
version: 0.6.1
|
133
133
|
type: :development
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.
|
139
|
+
version: 0.6.1
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: toys
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,14 +157,14 @@ dependencies:
|
|
157
157
|
requirements:
|
158
158
|
- - "~>"
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version: 0.
|
160
|
+
version: 0.4.0
|
161
161
|
type: :development
|
162
162
|
prerelease: false
|
163
163
|
version_requirements: !ruby/object:Gem::Requirement
|
164
164
|
requirements:
|
165
165
|
- - "~>"
|
166
166
|
- !ruby/object:Gem::Version
|
167
|
-
version: 0.
|
167
|
+
version: 0.4.0
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: rspec
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,28 +185,28 @@ dependencies:
|
|
185
185
|
requirements:
|
186
186
|
- - "~>"
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
version: 0.
|
188
|
+
version: 0.21.0
|
189
189
|
type: :development
|
190
190
|
prerelease: false
|
191
191
|
version_requirements: !ruby/object:Gem::Requirement
|
192
192
|
requirements:
|
193
193
|
- - "~>"
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: 0.
|
195
|
+
version: 0.21.0
|
196
196
|
- !ruby/object:Gem::Dependency
|
197
197
|
name: rubocop
|
198
198
|
requirement: !ruby/object:Gem::Requirement
|
199
199
|
requirements:
|
200
200
|
- - "~>"
|
201
201
|
- !ruby/object:Gem::Version
|
202
|
-
version:
|
202
|
+
version: '1.2'
|
203
203
|
type: :development
|
204
204
|
prerelease: false
|
205
205
|
version_requirements: !ruby/object:Gem::Requirement
|
206
206
|
requirements:
|
207
207
|
- - "~>"
|
208
208
|
- !ruby/object:Gem::Version
|
209
|
-
version:
|
209
|
+
version: '1.2'
|
210
210
|
- !ruby/object:Gem::Dependency
|
211
211
|
name: rubocop-performance
|
212
212
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,14 +227,14 @@ dependencies:
|
|
227
227
|
requirements:
|
228
228
|
- - "~>"
|
229
229
|
- !ruby/object:Gem::Version
|
230
|
-
version: '
|
230
|
+
version: '2.0'
|
231
231
|
type: :development
|
232
232
|
prerelease: false
|
233
233
|
version_requirements: !ruby/object:Gem::Requirement
|
234
234
|
requirements:
|
235
235
|
- - "~>"
|
236
236
|
- !ruby/object:Gem::Version
|
237
|
-
version: '
|
237
|
+
version: '2.0'
|
238
238
|
description: 'Standard Formalism forms for Sequel Models, such like create, find,
|
239
239
|
delete, etc.
|
240
240
|
|
@@ -274,14 +274,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
274
274
|
requirements:
|
275
275
|
- - ">="
|
276
276
|
- !ruby/object:Gem::Version
|
277
|
-
version: 2.5
|
277
|
+
version: '2.5'
|
278
|
+
- - "<"
|
279
|
+
- !ruby/object:Gem::Version
|
280
|
+
version: '4'
|
278
281
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
282
|
requirements:
|
280
283
|
- - ">="
|
281
284
|
- !ruby/object:Gem::Version
|
282
285
|
version: '0'
|
283
286
|
requirements: []
|
284
|
-
rubygems_version: 3.
|
287
|
+
rubygems_version: 3.2.3
|
285
288
|
signing_key:
|
286
289
|
specification_version: 4
|
287
290
|
summary: Standard Formalism forms for Sequel Models
|