tramway-core 1.11.2.1 → 1.12

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
  SHA256:
3
- metadata.gz: 37e67486fa7b4d30a04458655b613d872ecd1c4e04281831d7196c1af7a66844
4
- data.tar.gz: 4a45ed90f8a69a8c772ff1ac5c82cd139618b17e6417e9730cab89b67ab1b3f4
3
+ metadata.gz: 12be55503084db2c64bbfaa0b6ee9be832fcd59e69c310e07eb3fbc0898232fa
4
+ data.tar.gz: f2747d3bb5a1b1f75faac71cb841da9a6c1ad4bcd446c1f4729d7934f10ae685
5
5
  SHA512:
6
- metadata.gz: e1d7d0bb96e4af2272de7df6b71ebda6a445a89b06c2d2b7a816b5697d62a88fd12f316893fb0b84dd7125db0dff125d8702a7f23a7a59ba0a6121af0ed10194
7
- data.tar.gz: 13d6dd9a69f67cdff2f058bf376b38d3e93e4751ea49e127ab82585f41e983260b885a7a1301b4915f815f30252d4ce82fb8c42a4e09125514555dad31c4331e
6
+ metadata.gz: d4eb18d64363f2a6d67a47b957022944a9de037b83628ddb50fa01871adead0c3e6b69cbe1ad7673f60f3d1a27c01bd0edc12b12aa1bdabb122cf1e6b8f45bb7
7
+ data.tar.gz: 7cbda29bf51b732361615e14496629768a61be6e8af02dc52054cad30859643732e0e7d36ecee5ac68bd4752166ee8a6fd050a62fa55eda6751b2947d1e30f9c
@@ -118,6 +118,10 @@ module Tramway::Core
118
118
  def validation_group_class
119
119
  ActiveModel
120
120
  end
121
+
122
+ def validates(attribute, **options)
123
+ model_class.validates attribute, **options
124
+ end
121
125
  end
122
126
  end
123
127
  end
@@ -10,6 +10,12 @@ class Tramway::Core::ExtendableForm
10
10
  define_method 'submit' do |params|
11
11
  model.values ||= {}
12
12
  extended_params = params.except(*simple_properties.keys)
13
+ params.each do |key, value|
14
+ method_name = "#{key}="
15
+ if respond_to?(method_name)
16
+ send method_name, value
17
+ end
18
+ end
13
19
  model.values = extended_params.permit!.to_h.reduce(model.values) do |hash, pair|
14
20
  hash.merge! pair[0] => pair[1]
15
21
  end
@@ -25,7 +31,7 @@ class Tramway::Core::ExtendableForm
25
31
  end
26
32
  more_properties.reduce(hash) do |h, property|
27
33
  h.merge! property[0] => {
28
- extended_form_property: property[1]
34
+ extended_form_property: property[1][:object]
29
35
  }
30
36
  end
31
37
  end
@@ -34,6 +40,18 @@ class Tramway::Core::ExtendableForm
34
40
  define_method property[0] do
35
41
  model.values[property[0]] if model.values
36
42
  end
43
+
44
+ if property[1][:validates].present?
45
+ define_method "#{property[0]}=" do |value|
46
+ property[1][:validates].each do |pair|
47
+ validator_object = "#{pair[0].camelize}Validator".constantize.new({ attributes: :not_blank })
48
+ if pair[1] == 'true' && !validator_object.send(:valid?, value)
49
+ model.errors.add property[0],
50
+ I18n.t("activerecord.errors.models.#{model.class.name.underscore}.attributes.#{property[0]}.#{pair[0]}", { value: value })
51
+ end
52
+ end
53
+ end
54
+ end
37
55
  end
38
56
  end)
39
57
  end
@@ -17,3 +17,6 @@
17
17
  = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
18
18
  - else
19
19
  = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
20
+ - if params[:errors][field.title]&.first
21
+ .alert.alert-danger
22
+ = params[:errors][field.title]&.first
@@ -5,6 +5,7 @@ require 'tramway/error'
5
5
  require 'font_awesome5_rails'
6
6
  require 'reform'
7
7
  require 'pg_search'
8
+ require 'validators/presence_validator'
8
9
 
9
10
  module Tramway
10
11
  module Core
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Core
3
- VERSION = '1.11.2.1'
3
+ VERSION = '1.12'
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ class PresenceValidator
2
+ def initialize(attributes)
3
+ end
4
+
5
+ def valid?(value)
6
+ value.present?
7
+ end
8
+ 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.11.2.1
4
+ version: '1.12'
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-07-19 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reform-rails
@@ -376,6 +376,7 @@ files:
376
376
  - lib/tramway/core/version.rb
377
377
  - lib/tramway/error.rb
378
378
  - lib/tramway/helpers/class_name_helpers.rb
379
+ - lib/validators/presence_validator.rb
379
380
  homepage: https://github.com/kalashnikovisme/tramway-core
380
381
  licenses:
381
382
  - MIT