slim_form_object 1.0.7 → 1.0.8

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
  SHA1:
3
- metadata.gz: d2aed3c55c37bbeb4b8f1fa75688bcbf70eb6f6f
4
- data.tar.gz: cba65de38298064fcd60551819b2646b1d1b5026
3
+ metadata.gz: 7efb3cc1fcf933252927331cc874dcda2b0624f9
4
+ data.tar.gz: d2c0ba86d219f88539bde7f6544e85c8e0d8b8d0
5
5
  SHA512:
6
- metadata.gz: 3f32e57070632547c8670b7a23f9d7016384411e059fbe954a8578436c9af18a0e7f0edcd407c2c17b3f431bd867a0c8c49cf206f45f5f23bd8fa062890d4707
7
- data.tar.gz: d3038714911637b3f38a4eddc1daa7873481c2a2a23938f6472a5eba12f3c8d4b1b5b74c563b46eafcaa2e6bd74e27a965015d3a077eff77b93be63f313d1948
6
+ metadata.gz: 91ba6f3a12ff713405f879cf03eaa7a82351965599b675b670d9cd266c15e0a9b07ab44c68e25fdd48720ab7d9338b334889368710537c6fc30e76aa12698614
7
+ data.tar.gz: 49ec93ce2e22bc873881266f5e6fd6019b1ab36f6d2505016753c46fe49532fdf3a068164e9fa52ee249817b381fdb0ef4ff28c5e873c721f8c2130c112c5737
@@ -8,12 +8,10 @@ module SlimFormObject
8
8
  @form_object = form_object
9
9
  @params = form_object.params
10
10
  @array_all_objects_for_save = form_object.array_all_objects_for_save
11
- # @not_save_this_model = form_object.not_save_this_model
12
11
  @result_hash_updated_objects = {objects: [], nested_objects: {}}
13
12
  end
14
13
 
15
14
  def apply_parameters
16
- # filter_not_save_objects
17
15
  update_objects_attributes
18
16
  make_nested_objects
19
17
 
@@ -22,12 +20,6 @@ module SlimFormObject
22
20
 
23
21
  private
24
22
 
25
- # def filter_not_save_objects
26
- # array_all_objects_for_save.reject do |object|
27
- # not_save_this_model.include?(object.class)
28
- # end
29
- # end
30
-
31
23
  # STANDART OBJECTS
32
24
 
33
25
  def update_objects_attributes
@@ -43,6 +43,24 @@ module SlimFormObject
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ # CALLBACKS
48
+ def before_save_form(&block)
49
+ if block_given?
50
+ self.instance_eval do
51
+ define_method(:before_save_block) { block }
52
+ end
53
+ end
54
+ end
55
+
56
+ def after_save_form(&block)
57
+ if block_given?
58
+ self.instance_eval do
59
+ define_method(:after_save_block) { block }
60
+ end
61
+ end
62
+ end
63
+ # END CALLBACKS
46
64
  end
47
65
 
48
66
  def method_missing(name, *args, &block)
@@ -57,10 +75,10 @@ module SlimFormObject
57
75
  self.params = params
58
76
  get_or_add_default_objects
59
77
  end
60
- # INIT END
78
+ # END INIT
61
79
 
62
80
  def apply_parameters
63
- check_array_settings_with_settings
81
+ default_settings
64
82
  apply
65
83
  self
66
84
  end
@@ -95,8 +113,10 @@ module SlimFormObject
95
113
  end
96
114
  end
97
115
 
98
- def check_array_settings_with_settings
116
+ def default_settings
99
117
  define_singleton_method(:array_models_which_not_save_if_empty) { [] } unless respond_to?(:array_models_which_not_save_if_empty)
118
+ define_singleton_method(:after_save_block) { Proc.new {} } unless respond_to?(:after_save_block)
119
+ define_singleton_method(:before_save_block) { Proc.new {} } unless respond_to?(:before_save_block)
100
120
  end
101
121
 
102
122
  end
@@ -14,8 +14,10 @@ module SlimFormObject
14
14
  def save
15
15
  if form_object.valid?
16
16
  ActiveRecord::Base.transaction do
17
+ form_object.before_save_block.call(form_object)
17
18
  save_main_objects
18
19
  save_nested_objects
20
+ form_object.after_save_block.call(form_object)
19
21
  end
20
22
  return true
21
23
  end
@@ -44,6 +46,8 @@ module SlimFormObject
44
46
  end
45
47
  end
46
48
 
49
+
50
+
47
51
  def save_objects(object_1, object_2)
48
52
  object_for_save = to_bind_models(object_1, object_2)
49
53
  save_object(object_for_save)
@@ -1,3 +1,3 @@
1
1
  module SlimFormObject
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_form_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodcrust