formalism-model_forms 0.6.2 → 0.7.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 +4 -0
- data/lib/formalism/model_forms/_base.rb +26 -2
- data/lib/formalism/model_forms/delete.rb +1 -1
- 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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95151411e345c20bfa1f48b1d4b81b9b278d7a0d78d98f69479e9f4cea2fdc79
|
4
|
+
data.tar.gz: 73986aaeb3079d6e2b2a7416466f8b4be353f3b4792f0209a3bc1116bb6ddf38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0255a6211a4b6fea6a214763df0afaf02b16da026da6b338db047188e194a290880399f9bd87bd5c2ef6ad0b6cb04113d0b6e4e62336e5c6d056d89236272f3
|
7
|
+
data.tar.gz: 9c5a28f7ea6016437191f70f6c98e127a9c461d24500a30971d7ac360b1f0ab0f4908c7c91875b7ae1e6aa98c85e68bc8b4923744a1f50fde902c9f04281e33f
|
data/CHANGELOG.md
CHANGED
@@ -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,26 @@ module Formalism
|
|
34
36
|
form.alias_method "#{form.instance_name}=", :instance=
|
35
37
|
end
|
36
38
|
|
39
|
+
def included(something)
|
40
|
+
something.primary_field_name = primary_field_name
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_accessor :primary_field_name
|
44
|
+
|
45
|
+
def primary_field(name, *args, **kwargs)
|
46
|
+
remove_field primary_field_name if primary_field_name
|
47
|
+
|
48
|
+
field name, *args, **kwargs
|
49
|
+
|
50
|
+
self.primary_field_name = name
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_field(name)
|
54
|
+
super
|
55
|
+
|
56
|
+
self.primary_field_name = nil if name == primary_field_name
|
57
|
+
end
|
58
|
+
|
37
59
|
using GorillaPatch::Namespace
|
38
60
|
using GorillaPatch::Inflections
|
39
61
|
|
@@ -93,7 +115,9 @@ module Formalism
|
|
93
115
|
attr_writer :instance
|
94
116
|
|
95
117
|
def find_instance
|
96
|
-
model
|
118
|
+
model
|
119
|
+
.first(primary_field_name => public_send(primary_field_name))
|
120
|
+
.public_send(@cached ? :dup : :itself)
|
97
121
|
end
|
98
122
|
|
99
123
|
def field_condition(name, value)
|
@@ -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.7.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-
|
12
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alt_memery
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
- !ruby/object:Gem::Version
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
|
-
rubygems_version: 3.1.
|
284
|
+
rubygems_version: 3.1.4
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Standard Formalism forms for Sequel Models
|