slim_form_object 0.5.21 → 0.5.22

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: 877cf82dafb6d5693d503c5082512650aed41d5b
4
- data.tar.gz: f3ca78c6f2793d2cc4ea675f429b1980640f6df0
3
+ metadata.gz: 4a1a89125979213f45b4bf5df265aaaf83c0c4a9
4
+ data.tar.gz: 7b0a6cbab44b3b32c20d92d20e9d736f5c519b7b
5
5
  SHA512:
6
- metadata.gz: a134e57ba709ffee092dc233c48f44e3254093eab46b5a12a891b2d9ab5bde4f2bceab064d74076a5c5317d981f365a92ec052beabff7ebd64b5370e1754c76a
7
- data.tar.gz: 4b7e216b9556c3458d1113f2eafcb6af0eee02237099e6a1a8c3725ccd8b1e82777b4e6daa08fbc0e1968d9e0ad1608880a1a6b81f5d2eb3ddeea379fe57e61b
6
+ metadata.gz: 1e38ae5d94058cd6f8b6ee7171bc7d2fc85c41aec3ee2ce1a31203dd52bf912699bc25a08cf62d7890da55b38dd63024385145aa8133a6fae3e8852aa77a5e33
7
+ data.tar.gz: 51ed0c4650d16d2cde08d4670a3b1e3ec46900b37aa7a289783b861560ee351c3f8ac302eeca18c90b874be2c5897b76ebf946200d8b7f6c233d4f7f25d77566
@@ -37,6 +37,7 @@ module SlimFormObject
37
37
  end
38
38
 
39
39
  def submit
40
+ @array_of_models ||= array_of_models.reject{ |model| array_of_models_without_validates.include?(model) }
40
41
  update_attributes
41
42
  update_attributes_for_collection
42
43
  self
@@ -46,7 +47,7 @@ module SlimFormObject
46
47
 
47
48
  def save
48
49
  if valid?
49
- models = Array.new(array_of_models)
50
+ models = Array.new(@array_of_models)
50
51
  while model1 = models.delete( models[0] )
51
52
  models.each{ |model2| save_models(model1, model2) }
52
53
  end
@@ -55,30 +56,28 @@ module SlimFormObject
55
56
  false
56
57
  end
57
58
 
59
+ def not_validate(*args)
60
+ define_singleton_method(:array_of_models_without_validates) { args }
61
+ end
62
+
58
63
  private
59
64
 
60
65
  def save_models(model1, model2)
61
66
  self_object_of_model1 = method( snake(model1.to_s) ).call
62
67
  self_object_of_model2 = method( snake(model2.to_s) ).call
63
-
64
- case get_association(model1, model2)
65
- when :belongs_to
66
- self_object_of_model1.send( "#{snake(model2.to_s)}=", self_object_of_model2 )
67
- self_object_of_model1.save!
68
- when :has_one
69
- self_object_of_model1.send( "#{snake(model2.to_s)}=", self_object_of_model2 )
70
- self_object_of_model1.save!
71
- when :has_many
72
- self_object_of_model1.method("#{model2.table_name}").call << self_object_of_model2
73
- self_object_of_model1.save!
74
- when :has_and_belongs_to_many
75
- self_object_of_model1.method("#{model2.table_name}").call << self_object_of_model2
76
- self_object_of_model1.save!
68
+ association = get_association(model1, model2)
69
+
70
+ if association == :belongs_to or association == :has_one
71
+ self_object_of_model1.send( "#{snake(model2.to_s)}=", self_object_of_model2 )
72
+ self_object_of_model1.save!
73
+ elsif association == :has_many or association == :has_and_belongs_to_many
74
+ self_object_of_model1.method("#{model2.table_name}").call << self_object_of_model2
75
+ self_object_of_model1.save!
77
76
  end
78
77
  end
79
78
 
80
79
  def validation_models
81
- array_of_models.each do |model|
80
+ @array_of_models.each do |model|
82
81
  set_errors( method(snake(model.to_s)).call.errors ) unless method( snake(model.to_s) ).call.valid?
83
82
  end
84
83
  end
@@ -90,14 +89,14 @@ module SlimFormObject
90
89
  end
91
90
 
92
91
  def update_attributes
93
- array_of_models.each do |model|
92
+ @array_of_models.each do |model|
94
93
  model_attributes = make_attributes_of_model(model)
95
94
  method( snake(model.to_s) ).call.assign_attributes( get_attributes_for_update(model_attributes, model) )
96
95
  end
97
96
  end
98
97
 
99
98
  def update_attributes_for_collection
100
- array_of_models.each do |model|
99
+ @array_of_models.each do |model|
101
100
  assign_attributes_for_collection(model)
102
101
  end
103
102
  end
@@ -105,7 +104,7 @@ module SlimFormObject
105
104
  def keys_of_collections
106
105
  @keys ||= []
107
106
  params.keys.each do |key|
108
- array_of_models.each do |model|
107
+ @array_of_models.each do |model|
109
108
  self_object_of_model = method( snake(model.to_s) ).call
110
109
  method_name = key.to_s[/#{snake(model.to_s)}_(.*)/, 1]
111
110
  @keys << method_name if self_object_of_model.respond_to? method_name.to_s
@@ -116,7 +115,7 @@ module SlimFormObject
116
115
 
117
116
  def exist_any_errors_without_collections?
118
117
  keys_of_collections.each do |method_name|
119
- array_of_models.each do |model|
118
+ @array_of_models.each do |model|
120
119
  name_of_model = method_name.to_s[/^(.+)_ids$/, 1]
121
120
  name_of_constant_model = name_of_model.split('_').map(&:capitalize).join
122
121
  name_of_key_error = Object.const_get(name_of_constant_model).table_name
@@ -1,3 +1,3 @@
1
1
  module SlimFormObject
2
- VERSION = "0.5.21"
2
+ VERSION = "0.5.22"
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: 0.5.21
4
+ version: 0.5.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodcrust
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel