slim_form_object 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slim_form_object/version.rb +1 -1
- metadata +5 -6
- data/lib/slim_form_object/tmp.rb +0 -297
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d794f46de8a64093a4e262e7656f2c0276d1d0c2
|
4
|
+
data.tar.gz: 47a59625579728db477cd9a5017b1beb08b9bf3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa2c73239db19ad87c8adf78f26b69c48ec47accd1af8b3feece70e71298635c4ee46f2baedd1bea3ec616fa98fc6b30c97881e20f9e284b07157f69254dd44
|
7
|
+
data.tar.gz: 1270613ecd43269dfebfb8ec81922e99d738ae88f1f78652a74b2f7ff673b2a4f7191ea6c82cbc2799f31a43dd7006d6f47c6e49268b62936e91ff4d4829fbcb
|
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.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- woodcrust
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionview
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +166,6 @@ files:
|
|
166
166
|
- lib/slim_form_object/helpers.rb
|
167
167
|
- lib/slim_form_object/processing.rb
|
168
168
|
- lib/slim_form_object/saver.rb
|
169
|
-
- lib/slim_form_object/tmp.rb
|
170
169
|
- lib/slim_form_object/validator.rb
|
171
170
|
- lib/slim_form_object/version.rb
|
172
171
|
- spec/db/database.yml
|
data/lib/slim_form_object/tmp.rb
DELETED
@@ -1,297 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# require 'byebug'
|
10
|
-
|
11
|
-
# module SlimFormObject
|
12
|
-
# class Base
|
13
|
-
# attr_accessor :params
|
14
|
-
|
15
|
-
# def self.init_models(*args)
|
16
|
-
# self.instance_eval do
|
17
|
-
# define_method(:array_of_single_models) { args }
|
18
|
-
# end
|
19
|
-
# add_attributes(args)
|
20
|
-
# end
|
21
|
-
|
22
|
-
# alias_method :init_single_models, :init_models
|
23
|
-
|
24
|
-
# def self.init_multiple_models(*args)
|
25
|
-
# self.instance_eval do
|
26
|
-
# define_method(:array_multiple_models) { args }
|
27
|
-
# end
|
28
|
-
# add_attributes(args)
|
29
|
-
# end
|
30
|
-
|
31
|
-
# def self.add_attributes(models)
|
32
|
-
# #acessors for model objects
|
33
|
-
# models.each{ |model| attr_accessor snake(model.to_s).to_sym }
|
34
|
-
|
35
|
-
# #delegate attributes of models
|
36
|
-
# models.each do |model|
|
37
|
-
# model.column_names.each do |attr|
|
38
|
-
# delegate attr.to_sym, "#{attr}=".to_sym, to: snake(model.to_s).to_sym,
|
39
|
-
# prefix: true
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
|
44
|
-
# def self.set_model_name(name)
|
45
|
-
# define_method(:model_name) { ActiveModel::Name.new(self, nil, name) }
|
46
|
-
# end
|
47
|
-
# # def initializer
|
48
|
-
|
49
|
-
# # end
|
50
|
-
# end
|
51
|
-
|
52
|
-
# def self.included(base)
|
53
|
-
# # define_properties(base)
|
54
|
-
|
55
|
-
# base.include ActiveModel::Model
|
56
|
-
# base.include HelperMethods
|
57
|
-
# base.extend ClassMethods
|
58
|
-
# base.extend HelperMethods
|
59
|
-
# end
|
60
|
-
|
61
|
-
# # def self.define_properties(form_object_klass)
|
62
|
-
# # class << form_object_klass
|
63
|
-
# # #attr_accessor for models and env params
|
64
|
-
# # # attr_accessor :params
|
65
|
-
|
66
|
-
# # # byebug
|
67
|
-
|
68
|
-
# # # def params=(val)
|
69
|
-
# # # @params = val
|
70
|
-
# # # end
|
71
|
-
|
72
|
-
# # # def params
|
73
|
-
# # # @params
|
74
|
-
# # # end
|
75
|
-
# # end
|
76
|
-
# # end
|
77
|
-
|
78
|
-
# # module ClassMethods
|
79
|
-
|
80
|
-
# # def init_models(*args)
|
81
|
-
# # self.instance_eval do
|
82
|
-
# # define_method(:array_of_single_models) { args }
|
83
|
-
# # end
|
84
|
-
# # add_attributes(args)
|
85
|
-
# # end
|
86
|
-
|
87
|
-
# # alias_method :init_single_models, :init_models
|
88
|
-
|
89
|
-
# # def init_multiple_models(*args)
|
90
|
-
# # self.instance_eval do
|
91
|
-
# # define_method(:array_multiple_models) { args }
|
92
|
-
# # end
|
93
|
-
# # add_attributes(args)
|
94
|
-
# # end
|
95
|
-
|
96
|
-
# # def add_attributes(models)
|
97
|
-
# # #acessors for model objects
|
98
|
-
# # models.each{ |model| attr_accessor snake(model.to_s).to_sym }
|
99
|
-
|
100
|
-
# # #delegate attributes of models
|
101
|
-
# # models.each do |model|
|
102
|
-
# # model.column_names.each do |attr|
|
103
|
-
# # delegate attr.to_sym, "#{attr}=".to_sym, to: snake(model.to_s).to_sym,
|
104
|
-
# # prefix: true
|
105
|
-
# # end
|
106
|
-
# # end
|
107
|
-
# # end
|
108
|
-
|
109
|
-
# # def set_model_name(name)
|
110
|
-
# # define_method(:model_name) { ActiveModel::Name.new(self, nil, name) }
|
111
|
-
# # end
|
112
|
-
# # end
|
113
|
-
|
114
|
-
# def submit
|
115
|
-
# @array_of_single_models ||= array_of_single_models.reject do |model|
|
116
|
-
# array_of_single_models_without_validates.include?(model) if self.respond_to?(:array_of_single_models_without_validates)
|
117
|
-
# end
|
118
|
-
# update_attributes
|
119
|
-
# update_attributes_for_collection
|
120
|
-
# self
|
121
|
-
# end
|
122
|
-
|
123
|
-
# alias_method :apply_parameters, :submit
|
124
|
-
|
125
|
-
# def save
|
126
|
-
# if valid?
|
127
|
-
# models = Array.new(@array_of_single_models)
|
128
|
-
# while model1 = models.delete( models[0] )
|
129
|
-
# models.each{ |model2| save_models(model1, model2) }
|
130
|
-
# save_last_model_if_not_associations(model1) if models.empty?
|
131
|
-
# end
|
132
|
-
# return true
|
133
|
-
# end
|
134
|
-
# false
|
135
|
-
# end
|
136
|
-
|
137
|
-
# def not_validate(*args)
|
138
|
-
# define_singleton_method(:array_of_single_models_without_validates) { args }
|
139
|
-
# end
|
140
|
-
|
141
|
-
# private
|
142
|
-
|
143
|
-
# def save_models(model_1, model_2)
|
144
|
-
# self_object_of_model_for_save = nil
|
145
|
-
# byebug
|
146
|
-
# if both_model_attributes_exist?(model_1, model_2)
|
147
|
-
# # byebug
|
148
|
-
# self_object_of_model_for_save = to_bind_models(model_1, model_2)
|
149
|
-
# save_model(self_object_of_model_for_save)
|
150
|
-
# else
|
151
|
-
# get_self_objects_of_model(model_1, model_2).each do |object|
|
152
|
-
# save_model(object)
|
153
|
-
# end
|
154
|
-
# end
|
155
|
-
# end
|
156
|
-
|
157
|
-
# def to_bind_models(model_1, model_2)
|
158
|
-
# self_object_of_model_1, self_object_of_model_2 = get_self_objects_of_model(model_1, model_2)
|
159
|
-
# association = get_association(model_1, model_2)
|
160
|
-
|
161
|
-
# if association == :belongs_to or association == :has_one
|
162
|
-
# self_object_of_model_1.send( "#{snake(model_2.to_s)}=", self_object_of_model_2 )
|
163
|
-
# elsif association == :has_many or association == :has_and_belongs_to_many
|
164
|
-
# self_object_of_model_1.method("#{model_2.table_name}").call << self_object_of_model_2
|
165
|
-
# end
|
166
|
-
|
167
|
-
# self_object_of_model_1
|
168
|
-
# end
|
169
|
-
|
170
|
-
# def valid_model_for_save?(model)
|
171
|
-
# ( (attributes_is_present?(model) and method( snake(model.to_s) ).call.id != nil) or (method( snake(model.to_s) ).call.id == nil and !all_attributes_is_empty?(model)) )
|
172
|
-
# end
|
173
|
-
|
174
|
-
# def attributes_is_present?(model)
|
175
|
-
# (make_attributes_of_model(model) & params.keys).present?
|
176
|
-
# end
|
177
|
-
|
178
|
-
# def both_model_attributes_exist?(model_1, model_2)
|
179
|
-
# valid_model_for_save?(model_1) and valid_model_for_save?(model_2)
|
180
|
-
# end
|
181
|
-
|
182
|
-
# def save_model(self_object_of_model)
|
183
|
-
# if valid_model_for_save?(self_object_of_model.class)
|
184
|
-
# self_object_of_model.save!
|
185
|
-
# end
|
186
|
-
# end
|
187
|
-
|
188
|
-
# def all_attributes_is_empty?(model)
|
189
|
-
# is_empty = true
|
190
|
-
# array_symbols_of_attributes = (make_attributes_of_model(model) & params.keys).map { |attr| attr.to_sym }
|
191
|
-
# params.slice(*array_symbols_of_attributes).values.each do |value|
|
192
|
-
# is_empty = false unless value == ""
|
193
|
-
# end
|
194
|
-
# is_empty
|
195
|
-
# end
|
196
|
-
|
197
|
-
# def get_self_objects_of_model(model_1, model_2)
|
198
|
-
# [ method( snake(model_1.to_s) ).call, method( snake(model_2.to_s) ).call ]
|
199
|
-
# end
|
200
|
-
|
201
|
-
# def save_last_model_if_not_associations(model)
|
202
|
-
# association_trigger = false
|
203
|
-
# self_object_of_model = method( snake(model.to_s) ).call
|
204
|
-
# @array_of_single_models.each { |model2| association_trigger = true if get_association(model, model2) }
|
205
|
-
# self_object_of_model.save unless association_trigger
|
206
|
-
# rescue
|
207
|
-
# self_object_of_model.class.find(self_object_of_model.id).update!(self_object_of_model.attributes)
|
208
|
-
# end
|
209
|
-
|
210
|
-
# def validation_models
|
211
|
-
# @array_of_single_models.each do |model|
|
212
|
-
# next unless valid_model_for_save?(model)
|
213
|
-
# set_errors( method(snake(model.to_s)).call.errors ) unless method( snake(model.to_s) ).call.valid?
|
214
|
-
# end
|
215
|
-
# end
|
216
|
-
|
217
|
-
# def set_errors(model_errors)
|
218
|
-
# model_errors.each do |attribute, message|
|
219
|
-
# errors.add(attribute, message)
|
220
|
-
# end
|
221
|
-
# end
|
222
|
-
|
223
|
-
# def update_attributes
|
224
|
-
# @array_of_single_models.each do |model|
|
225
|
-
# model_attributes = make_attributes_of_model(model)
|
226
|
-
# method( snake(model.to_s) ).call.assign_attributes( get_attributes_for_update(model_attributes, model) )
|
227
|
-
# end
|
228
|
-
# end
|
229
|
-
|
230
|
-
# def update_attributes_for_collection
|
231
|
-
# @array_of_single_models.each do |model|
|
232
|
-
# assign_attributes_for_collection(model)
|
233
|
-
# end
|
234
|
-
# end
|
235
|
-
|
236
|
-
# def keys_of_collections
|
237
|
-
# @keys ||= []
|
238
|
-
# params.keys.each do |key|
|
239
|
-
# @array_of_single_models.each do |model|
|
240
|
-
# self_object_of_model = method( snake(model.to_s) ).call
|
241
|
-
# method_name = key.to_s[/#{snake(model.to_s)}_(.*)/, 1]
|
242
|
-
# @keys << method_name if self_object_of_model.respond_to? method_name.to_s
|
243
|
-
# end if key[/^.+_ids$/]
|
244
|
-
# end if @keys.empty?
|
245
|
-
# @keys
|
246
|
-
# end
|
247
|
-
|
248
|
-
# def exist_any_errors_without_collections?
|
249
|
-
# keys_of_collections.each do |method_name|
|
250
|
-
# @array_of_single_models.each do |model|
|
251
|
-
# name_of_model = method_name.to_s[/^(.+)_ids$/, 1]
|
252
|
-
# name_of_constant_model = name_of_model.split('_').map(&:capitalize).join
|
253
|
-
# name_of_key_error = Object.const_get(name_of_constant_model).table_name
|
254
|
-
# errors.messages.delete(name_of_key_error.to_sym)
|
255
|
-
# end
|
256
|
-
# end unless valid?
|
257
|
-
# errors.messages.empty?
|
258
|
-
# end
|
259
|
-
|
260
|
-
# def assign_attributes_for_collection(model)
|
261
|
-
# self_object_of_model = method( snake(model.to_s) ).call
|
262
|
-
|
263
|
-
# keys_of_collections.each do |method_name|
|
264
|
-
# if self_object_of_model.respond_to? method_name
|
265
|
-
# old_attribute = self_object_of_model.method( method_name ).call
|
266
|
-
# unless self_object_of_model.update_attributes( {method_name.to_s => params["#{snake(model.to_s)}_#{method_name}".to_sym]} )
|
267
|
-
# set_errors(self_object_of_model.errors)
|
268
|
-
# self_object_of_model.update_attributes( {method_name.to_s => old_attribute} )
|
269
|
-
# end if exist_any_errors_without_collections?
|
270
|
-
# end
|
271
|
-
# end
|
272
|
-
# end
|
273
|
-
|
274
|
-
# def make_attributes_of_model(model)
|
275
|
-
# model_attributes = []
|
276
|
-
# model.column_names.each do |name|
|
277
|
-
# model_attributes << "#{snake(model.to_s)}_#{name}"
|
278
|
-
# end
|
279
|
-
# model_attributes
|
280
|
-
# end
|
281
|
-
|
282
|
-
# def get_attributes_for_update(model_attributes, model)
|
283
|
-
# attributes_for_update = {}
|
284
|
-
# hash_attributes = params.slice(*model_attributes)
|
285
|
-
# hash_attributes.each{ |attr, val| attributes_for_update[attr.gsub(/#{snake(model.to_s)}_(.*)/, '\1')] = val }
|
286
|
-
# attributes_for_update
|
287
|
-
# end
|
288
|
-
|
289
|
-
# def get_association(class1, class2)
|
290
|
-
# class1.reflections.slice(snake(class2.to_s), class2.table_name).values.first&.macro
|
291
|
-
# end
|
292
|
-
|
293
|
-
|
294
|
-
# # get attributes
|
295
|
-
# # .gsub(/^\[|\]$|"/, '').split(', ')
|
296
|
-
|
297
|
-
# end
|