slim_form_object 3.2.0 → 3.3.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: f7789745013fc14bc053cbfce3982ecfbaac028d925135abd6ac4729129746df
4
- data.tar.gz: 2c679b2b95f1abccd9371b2b8502ff3dffbbf2c30b5588b619e07ffd528dbfe0
3
+ metadata.gz: f1aba71a3861a1e7e07527da38d6c57ba6b7bdd1a1deeec053fa3dc54c978d89
4
+ data.tar.gz: 98ba1923cffddde9e7056f47a64960f08feff5e2f3eccff5ed299a684db4bb3c
5
5
  SHA512:
6
- metadata.gz: 56c1956ea98aa65d6f6d1ac159815ff947966550a21610ecea271bf7a19fa049fe38bee7599a8a9dd52dc4531d9c2923619da833280004807c7e5e08df892709
7
- data.tar.gz: 6b8e22e5b95f2f246cba5f80caf9aeb22bbe27c53173bbe712a252ae11a9dfbd5a830f02edf551a2cf36d55b5123051e4e22987d5d9945b482e5e16e99345b0b
6
+ metadata.gz: 00a70a593909ac03267b9d942117f471da1bba88b62bc0911203ea3ae1e7d7c5c691777aa85dd0538e526e0a786c9b2afbcb90613e9d76a5fa6d3686867c2085
7
+ data.tar.gz: 996361026ca64372eeedffeeb81b093b97df24a3c0db2916208229236a83e1ff107ffca253263d645c0ae973a9cc023a63de668941af015d09146343124f3e95
@@ -15,7 +15,9 @@ module SlimFormObject
15
15
  end
16
16
 
17
17
  def apply_parameters_and_make_objects
18
- parse_params
18
+ form_object.check_params_block.call(form_object, params)
19
+
20
+ parse_params(params)
19
21
  @data_objects_arr = make_data_objects(data_for_assign)
20
22
  clean_data_objects_arr(data_objects_arr)
21
23
  associate_all_objects(data_objects_arr)
@@ -65,7 +67,7 @@ module SlimFormObject
65
67
  values.select{ |key, value| key.to_i.to_s == key }.size == values.size
66
68
  end
67
69
 
68
- def parse_params
70
+ def parse_params(params)
69
71
  params.to_h.each do |main_model_name, attributes|
70
72
  data_for_assign << make_hash_objects_and_nested_objects(main_model_name, attributes)
71
73
  end
@@ -36,7 +36,15 @@ module HelperMethods
36
36
  end
37
37
 
38
38
  def get_reflection(class1, class2)
39
- class1.reflections.select{ |k,v| v.klass == class2 }.values.first
39
+ class1.reflections.select do |k,v|
40
+ if v&.options&.send(:[], :polymorphic)
41
+ if class2.reflections.select{ |k,v| v.klass == class1 }.values.first
42
+ true
43
+ end
44
+ else
45
+ v.klass == class2
46
+ end
47
+ end.values.first
40
48
  end
41
49
 
42
50
  def type_association(reflection)
@@ -29,7 +29,8 @@ module SlimFormObject
29
29
  'after_save_object',
30
30
  'allow_to_save_object',
31
31
  'allow_to_validate_object',
32
- 'allow_object_processing'
32
+ 'allow_object_processing',
33
+ 'check_params'
33
34
  ].each do |method_name|
34
35
  define_method("#{method_name}".to_sym) do |&block|
35
36
  instance_eval do
@@ -133,6 +134,7 @@ module SlimFormObject
133
134
  def default_settings
134
135
  define_singleton_method(:after_validation_form_block) { Proc.new {} } unless respond_to?(:after_validation_form_block)
135
136
  define_singleton_method(:after_save_form_block) { Proc.new {} } unless respond_to?(:before_save_form_block)
137
+ define_singleton_method(:check_params_block) { Proc.new {} } unless respond_to?(:check_params_block)
136
138
  define_singleton_method(:after_save_object_block) { Proc.new { true } } unless respond_to?(:allow_to_save_object_block)
137
139
  define_singleton_method(:allow_to_validate_object_block) { Proc.new { true } } unless respond_to?(:allow_to_validate_object_block)
138
140
 
@@ -1,3 +1,3 @@
1
1
  module SlimFormObject
2
- VERSION = "3.2.0"
2
+ VERSION = "3.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_form_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodcrust
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel