isomorfeus-react 16.12.15 → 16.12.16

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: c52d4071118b2aaf2dda6e7822a3954f9ce3ef2b4bdd846bd98d79658d0b35b3
4
- data.tar.gz: 5e5aa6e03f9bd9e749ff9c8b096160c599d1c6402ee7ddbcf7afa1ebb3983ade
3
+ metadata.gz: c51e1ae7cb26a3240215e958cf0f605f65cc048f3f0280f06be1af1019b0c667
4
+ data.tar.gz: 7820879dd2c4131dea2a133b0d80ec8509ef4ed80fec87bb1315b57e191cbf1d
5
5
  SHA512:
6
- metadata.gz: 2bb47191b1f7c54b62f87fdd57aee0bd5515587dccd3afd1253ace005abcf2cce17bc0072e37a32f71938c0c6e998cf765fb42dd0e2ec713dd2afd1ed68eb7ea
7
- data.tar.gz: 9b2973a335e84430ef3e92063d92957fad546032037a0357d8cd6aa0cc9030de0504c022ac066f19fc5aac29959351c4c4f0f8a65c801e3c0da359e084e65736
6
+ metadata.gz: 7a81c98464f696bef417dbc0cceb1c8acd851ff27338d6270527b0b7ff87759fa78cd04f86764b0361cec6b4e3a4f36e85da5e03fc52dbb38f13c851c0bfa78c
7
+ data.tar.gz: 147a51fb0e634a5ed0089c164445ea8981f7cd6bd5bfabb7f5223f1ce6268ade29486c188b6c1c0a2a9567448ddc8677fc31991ecbddf2517c8a5b829a160080
@@ -124,6 +124,11 @@ module Isomorfeus
124
124
  alias_method :condition, :test
125
125
  alias_method :check, :test
126
126
 
127
+ def validate_block(&block)
128
+ @validation_hash[:validate][:validate_block] = block
129
+ self
130
+ end
131
+
127
132
  # types
128
133
 
129
134
  def Array
@@ -11,6 +11,7 @@ module Isomorfeus
11
11
  def validate!
12
12
  ensured = ensure!
13
13
  unless ensured
14
+ set_default_value
14
15
  cast!
15
16
  type!
16
17
  end
@@ -18,10 +19,20 @@ module Isomorfeus
18
19
  true
19
20
  end
20
21
 
22
+ def validated_value
23
+ validate!
24
+ @v
25
+ end
26
+
21
27
  private
22
28
 
23
29
  # basic tests
24
30
 
31
+ def set_default_value
32
+ return unless @v.nil?
33
+ @v = @o[:default] if @o.key?(:default)
34
+ end
35
+
25
36
  def cast!
26
37
  if @o.key?(:cast)
27
38
  begin
@@ -73,6 +84,7 @@ module Isomorfeus
73
84
  send('c_' + m, l)
74
85
  end
75
86
  end
87
+ @o[:validate_block].call(@v) if @o.key?(:validate_block)
76
88
  end
77
89
 
78
90
  # specific validations
@@ -93,5 +93,28 @@ module LucidPropDeclaration
93
93
  end
94
94
  result
95
95
  end
96
+
97
+ def validated_prop(prop, value)
98
+ nil unless declared_props.key?(prop)
99
+ validator = Isomorfeus::Props::Validator.new(self, prop, value, declared_props[prop])
100
+ validator.validated_value
101
+ end
102
+
103
+ def validated_props(props)
104
+ props = {} unless props
105
+
106
+ declared_props.each_key do |prop|
107
+ if declared_props[prop].key?(:required) && declared_props[prop][:required] && !props.key?(prop)
108
+ Isomorfeus.raise_error(message: "Required prop #{prop} not given!")
109
+ end
110
+ props[prop] = nil unless props.key?(prop) # let validator handle value
111
+ end
112
+
113
+ result = {}
114
+ props.each do |p, v|
115
+ result[p] = validated_prop(p, v)
116
+ end
117
+ result
118
+ end
96
119
  end
97
120
  end
@@ -58,9 +58,21 @@ module React
58
58
  end
59
59
  end
60
60
 
61
+ def to_h
62
+ `Opal.Hash.$new(#@native)`
63
+ end
64
+
65
+ def to_json
66
+ JSON.dump(to_transport)
67
+ end
68
+
61
69
  def to_n
62
70
  @native.JS[:props]
63
71
  end
72
+
73
+ def to_transport
74
+ {}.merge(to_h)
75
+ end
64
76
  end
65
77
  end
66
78
  end
@@ -1,3 +1,3 @@
1
1
  module React
2
- VERSION = '16.12.15'
2
+ VERSION = '16.12.16'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-react
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.12.15
4
+ version: 16.12.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-05 00:00:00.000000000 Z
11
+ date: 2020-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -277,7 +277,7 @@ metadata:
277
277
  github_repo: ssh://github.com/isomorfeus/gems
278
278
  post_install_message: |2+
279
279
 
280
- isomorfeus-react 16.12.15:
280
+ isomorfeus-react 16.12.16:
281
281
  Breaking change:
282
282
  The event_handler DSL is gone. Instead use normal methods and method_ref, see:
283
283
  https://github.com/isomorfeus/isomorfeus-react/blob/master/ruby/docs/events.md