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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57e9e6077948f6108a399e2bae336e72107022b28120bc0278be0a0b05b0a6ca
4
- data.tar.gz: 69eb5613bad324817f826cffff430de81baf7822a18d43748b5df77dbae4c42d
3
+ metadata.gz: cb6265733b776ca5782e1aba24dddc3c970757a89d9bb98471d98a920aa9a505
4
+ data.tar.gz: c043043ca1857d578e7640048cd506bd4f8c6ed20e2105f8f0372e9f0a1d4b5e
5
5
  SHA512:
6
- metadata.gz: abd8a9b8110e2b69dedc06e8a64861951cf2059508287b43c3412f4dd05d631036809294a6f3ab1b4a2861e3b09773e11ff341898a1ae17a48977aa1c6c1fa8c
7
- data.tar.gz: 0f4ac0480a4939d07acc968058dd03f36f39c24530446d52f66827e735acee0cb5e267d5ce086bb1b04a1b413852b6de565714e181281c01c1845e87bcb0a051
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__ - 4
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.const_defined?(part, false) || part == 'Model' }
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[id].public_send(@cached ? :dup : :itself)
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
- field :id, Integer
19
+ primary_field :id, Integer
20
20
 
21
21
  private
22
22
 
23
23
  def execute
24
- instance.changes_author = changes_author if model.auditable?
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
@@ -7,7 +7,7 @@ module Formalism
7
7
  include Formalism::ModelForms::Base
8
8
  include Memery
9
9
 
10
- field :id, Integer, default: nil
10
+ primary_field :id, Integer, default: nil
11
11
 
12
12
  def initialize(params_or_instance = {})
13
13
  if params_or_instance.is_a?(Hash)
@@ -11,11 +11,20 @@ module Formalism
11
11
  def inherited(child_form)
12
12
  super
13
13
 
14
- child_form.nested :find, child_form.namespace::Find,
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
- errors_key: nil
25
+ merge_errors: false
17
26
 
18
- child_form.nested :create, child_form.namespace::Create,
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(:id) unless unfiltered_dataset.opts[: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(id: dataset.select(:id).limit(limit_by_page))
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
- field :id, Integer
9
+ primary_field :id, Integer
10
10
 
11
11
  attr_reader :direction
12
12
 
13
- def initialize(direction, id, how_many = 1)
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(id: id)
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
- field :id, Array, of: Integer, default: []
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
- field :id, Integer, merge: false
24
+ primary_field :id, Integer, merge: false
25
25
 
26
- def initialize(params, id_or_instance)
27
- if id_or_instance.is_a?(model)
28
- self.instance = id_or_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
- self.id = id_or_instance
30
+ public_send "#{primary_field_name}=", pf_or_instance
31
31
  end
32
32
 
33
33
  super params || {}
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Formalism
4
4
  module ModelForms
5
- VERSION = '0.6.1'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
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.6.1
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: 2020-09-27 00:00:00.000000000 Z
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.2.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.2.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.4.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.4.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.2.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.2.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.19.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.19.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: 0.92.0
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: 0.92.0
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: '1.0'
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: '1.0'
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.0
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.1.2
287
+ rubygems_version: 3.2.3
285
288
  signing_key:
286
289
  specification_version: 4
287
290
  summary: Standard Formalism forms for Sequel Models