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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac6934a45b110aec6928cb8a4a04245be5869e652a6120cc4e5e411f1b4762ce
4
- data.tar.gz: 6f7dfc4d1bc40657739eee946f007d324016ccee51e036d609965aa001ed98da
3
+ metadata.gz: 95151411e345c20bfa1f48b1d4b81b9b278d7a0d78d98f69479e9f4cea2fdc79
4
+ data.tar.gz: 73986aaeb3079d6e2b2a7416466f8b4be353f3b4792f0209a3bc1116bb6ddf38
5
5
  SHA512:
6
- metadata.gz: 6a444fb88a4b2c982d627bf1b7e6eb664a3777d9b033fc28d2d3cbfaccb6901ce241a56322dc497497ef47f09150beaf74e0de7e0b3bfb4d24f59807d4142047
7
- data.tar.gz: f1f7a1350bc894c938cdf552b2a521abd65d42d2bbcca79dd36753c1d35be85d5a7285f81f8d852bef432ef7f3c115d7ecda7d7828ae1c447dc9139800c3eebe
6
+ metadata.gz: c0255a6211a4b6fea6a214763df0afaf02b16da026da6b338db047188e194a290880399f9bd87bd5c2ef6ad0b6cb04113d0b6e4e62336e5c6d056d89236272f3
7
+ data.tar.gz: 9c5a28f7ea6016437191f70f6c98e127a9c461d24500a30971d7ac360b1f0ab0f4908c7c91875b7ae1e6aa98c85e68bc8b4923744a1f50fde902c9f04281e33f
@@ -2,8 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.7.0 (2020-10-14)
6
+
5
7
  ## 0.6.2 (2020-09-28)
6
8
 
9
+ * Update `formalism` to a new version.
10
+
7
11
  ## 0.6.1 (2020-09-28)
8
12
 
9
13
  * Fix case when there is instance and `nil` params for `Update` form.
@@ -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[id].public_send(@cached ? :dup : :itself)
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)
@@ -16,7 +16,7 @@ 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
 
@@ -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.2'
5
+ VERSION = '0.7.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.2
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-09-28 00:00:00.000000000 Z
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.2
284
+ rubygems_version: 3.1.4
285
285
  signing_key:
286
286
  specification_version: 4
287
287
  summary: Standard Formalism forms for Sequel Models