tramway-core 1.14.1.2 → 1.14.2.4

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: 8e37bc7fd023ce8768a173d48b50575ac71538cb27078c8cabf2d4aaf996c53c
4
- data.tar.gz: 253c5c1543f25b34905341bdc11d9a31e84737cf11a2c1e547c5f0c3d9d16cb6
3
+ metadata.gz: 83e5c3f0d70596f3ebaa37ecee23ceef049e69332bce0005bfb065b7c969766b
4
+ data.tar.gz: bc7b8f743cdda6eb446d500058263580c894a4259184cc99c7ef0abddfcdaa7f
5
5
  SHA512:
6
- metadata.gz: 2bb111d0932442985c8a93edd2e3c0acfdeef417565d032560f895584e8efb783c9f3a1323688f8680a29a0cf95485c658e2029b4b0e78f10c7f536374484f20
7
- data.tar.gz: fd7a7cdcc2b47374e1c1405b1278219ba4e7e17fc0209bf22895339d24c619d2156a5af641c16b5423ad0ed0ae1ea95f738d1c669938e1015d251d5205aaca27
6
+ metadata.gz: db01de1fe36af20e77b0f50f3950dd274bd1cfe18c8a3bd2174d1e8c1521ef9a2e8f08e8eca83b5e609093604ed00c738765ebf66fb51e332bc40c680a7a8d68
7
+ data.tar.gz: aa7e0bafceeb1822da3375551a9551d7d15124d279ff841184450eefe93b4ddfe91bcc1a8613de806fb5819984aa07dd03f82509fbb11b7015a31091435a0791
@@ -33,7 +33,15 @@ module Tramway::Core
33
33
  def submit(params)
34
34
  if params
35
35
  if validate params
36
- save
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
@@ -58,11 +69,17 @@ module Tramway::Core
58
69
  @form_properties = args
59
70
  end
60
71
 
72
+ def form_properties_additional(**args)
73
+ @form_properties_additional = args
74
+ end
75
+
61
76
  def properties
62
77
  return @form_properties if @form_properties
63
78
  yaml_config_file_path = Rails.root.join('app', 'forms', "#{self.class.name.underscore}.yml")
64
79
  if File.exist? yaml_config_file_path
65
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
66
83
  else
67
84
  []
68
85
  end
@@ -138,13 +155,39 @@ module Tramway::Core
138
155
  end
139
156
  end
140
157
 
158
+ def model_class=(name)
159
+ @@model_class = name
160
+ end
161
+
141
162
  def validation_group_class
142
163
  ActiveModel
143
164
  end
144
165
 
145
166
  def validates(attribute, **options)
146
- 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
147
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
148
191
  end
149
192
  end
150
193
  end
@@ -20,7 +20,7 @@ module Tramway
20
20
 
21
21
  scope :active, -> { where state: :active }
22
22
 
23
- include ::PgSearch
23
+ include ::PgSearch::Model
24
24
 
25
25
  # FIXME: detect inhertited locales
26
26
  class << self
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.14.1.2'
5
+ VERSION = '1.14.2.4'
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.2
4
+ version: 1.14.2.4
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-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited