tramway-core 1.14.1.1 → 1.14.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dd03e903c3da051f37a4eefbb5e54a5efe47484cc37d3362ff1162edd25f440
4
- data.tar.gz: 6d0f3fac662adafee2f7065918cc56fdf1a68c7c6e133f1f254ba5b0790c355e
3
+ metadata.gz: c9820c9e325290379c9a5ad29f176d676cc704b89bfc1d860c44d18671c8da02
4
+ data.tar.gz: c1e52196bdbdf3fe0bf2b2c818ea29b42101daf482a901a6bf637895eb605dba
5
5
  SHA512:
6
- metadata.gz: c101e099080222ec11205155027a70493232181ee3c528bcf8fd13937e1c6e2eb318768d911ec8e9d5215c8c8eceb52946743c18f2ed0fd68676de18f3a19ba8
7
- data.tar.gz: 220af3ce5f627bc11578324e5d17245140f77ffcd59c676c76ff24d804f57cd6ffdd0f79b7fdd8fe882f7ef2381c715b81939a91513a4efbe89d712a763b32c2
6
+ metadata.gz: dad84b3585783d587299f0bf2d22e3d07dfef30f37c8f2a1a0c077d6defac10327495a6f836058a10a82711c6ab7c56b4be73ae2c43808b65e7621be99e3c5ea
7
+ data.tar.gz: 499cbb454235a26170f0dee382e38eb9eeaffb74eb1e4e7aac6c24f5763198eccdc3a92ff041bcd19f7d238f02e36ac0a220ecf64f60c906e03c9601429a57f0
@@ -32,8 +32,30 @@ module Tramway::Core
32
32
 
33
33
  def submit(params)
34
34
  if params
35
- save if validate params
35
+ if validate params
36
+ begin
37
+ save.tap do
38
+ #self.class.remove_validations_from_model!
39
+ end
40
+ rescue StandardError => e
41
+ #self.class.remove_validations_from_model!
42
+ error = Tramway::Error.new(plugin: :core, method: :submit, message: "Looks like you have method `#{e.name.to_s.gsub('=', '')}` in #{@@model_class}. You should rename it or rename property in #{self.class}")
43
+ raise error.message
44
+ end
45
+ else
46
+ association_error = false
47
+ @@associations.each do |association|
48
+ if errors.details[association] == [{ error: :blank }]
49
+ model.send("#{association}=", send(association))
50
+ association_error = true
51
+ end
52
+ end
53
+ (association_error && save).tap do
54
+ #self.class.remove_validations_from_model!
55
+ end
56
+ end
36
57
  else
58
+ #self.class.remove_validations_from_model!
37
59
  error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
38
60
  raise error.message
39
61
  end
@@ -47,11 +69,17 @@ module Tramway::Core
47
69
  @form_properties = args
48
70
  end
49
71
 
72
+ def form_properties_additional(**args)
73
+ @form_properties_additional = args
74
+ end
75
+
50
76
  def properties
51
77
  return @form_properties if @form_properties
52
78
  yaml_config_file_path = Rails.root.join('app', 'forms', "#{self.class.name.underscore}.yml")
53
79
  if File.exist? yaml_config_file_path
54
80
  @form_properties = YAML.load_file(yaml_config_file_path).deep_symbolize_keys
81
+ @form_properties.deep_merge! @form_properties_additional if @form_properties_additional
82
+ @form_properties
55
83
  else
56
84
  []
57
85
  end
@@ -127,13 +155,39 @@ module Tramway::Core
127
155
  end
128
156
  end
129
157
 
158
+ def model_class=(name)
159
+ @@model_class = name
160
+ end
161
+
130
162
  def validation_group_class
131
163
  ActiveModel
132
164
  end
133
165
 
134
166
  def validates(attribute, **options)
135
- model_class.validates attribute, **options
167
+ if !defined?(@@model_class) || @@model_class.nil?
168
+ error = Tramway::Error.new(plugin: :core, method: :validates, message: "You need to set `model_class` name while using validations. Just write `self.model_class = YOUR_MODEL_NAME` in the class area.")
169
+ raise error.message
170
+ end
171
+ @@model_class.validates attribute, **options
172
+ # @@validations ||= {}
173
+ # @@validations.deep_merge! attribute => options
136
174
  end
175
+
176
+ # FIXME: Removes all validations in a field. We must implement own validations
177
+
178
+ #def remove_validations_from_model!
179
+ # return unless defined? @@validations
180
+ # @@validations&.each do |validation|
181
+ # @@model_class.class_eval do
182
+ # _validators.except validation[0]
183
+ #
184
+ # binding.pry
185
+ # _validate_callbacks.each do |callback|
186
+ # callback.raw_filter.attributes.delete validation[0]
187
+ # end
188
+ # end
189
+ # end
190
+ #end
137
191
  end
138
192
  end
139
193
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.14.1.1'
5
+ VERSION = '1.14.2.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.1.1
4
+ version: 1.14.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2019-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited