tramway-core 1.14.2 → 1.14.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4097c0630d7dcef57b863d746510bb92826a738381c9f14aeb6dd60ac88ad5a9
|
4
|
+
data.tar.gz: b554f9e93d3b656237764ab63f728e4042f36e239d1ddafa346fcc9fcc9dd377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94489bf533fa58eaf2a10940dc38afa24d4f6e92247b4979f7557c2d895bcdf3e6700a4634024f6df34a9a801c28581a13320815985890b9398fa44266b99e6c
|
7
|
+
data.tar.gz: 65f11aca85093709c7f87a669777fdce19b4a3797d9c7c369ad6dcbe0c26efbcec8ca67e26f1f5ce13a7d1a6b8f441350c324a7b0090c30a695a1c71dbdf2fe5
|
@@ -54,6 +54,10 @@ class Tramway::Core::ApplicationDecorator
|
|
54
54
|
|
55
55
|
define_method association_name do
|
56
56
|
association = object.class.reflect_on_association(association_name)
|
57
|
+
if association.nil?
|
58
|
+
error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Model #{object.class} does not have association named `#{association_name}`")
|
59
|
+
raise error.message
|
60
|
+
end
|
57
61
|
class_name = if association.polymorphic?
|
58
62
|
object.send(association_name).class
|
59
63
|
else
|
@@ -33,7 +33,15 @@ module Tramway::Core
|
|
33
33
|
def submit(params)
|
34
34
|
if params
|
35
35
|
if validate params
|
36
|
-
|
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
|
37
45
|
else
|
38
46
|
association_error = false
|
39
47
|
@@associations.each do |association|
|
@@ -42,9 +50,12 @@ module Tramway::Core
|
|
42
50
|
association_error = true
|
43
51
|
end
|
44
52
|
end
|
45
|
-
association_error && save
|
53
|
+
(association_error && save).tap do
|
54
|
+
#self.class.remove_validations_from_model!
|
55
|
+
end
|
46
56
|
end
|
47
57
|
else
|
58
|
+
#self.class.remove_validations_from_model!
|
48
59
|
error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
|
49
60
|
raise error.message
|
50
61
|
end
|
@@ -144,13 +155,39 @@ module Tramway::Core
|
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|
158
|
+
def model_class=(name)
|
159
|
+
@@model_class = name
|
160
|
+
end
|
161
|
+
|
147
162
|
def validation_group_class
|
148
163
|
ActiveModel
|
149
164
|
end
|
150
165
|
|
151
166
|
def validates(attribute, **options)
|
152
|
-
model_class
|
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
|
153
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
|
154
191
|
end
|
155
192
|
end
|
156
193
|
end
|
data/lib/tramway/core/version.rb
CHANGED
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.
|
4
|
+
version: 1.14.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
|
+
date: 2019-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: audited
|