vident 0.4.1 → 0.5.0
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 +4 -4
- data/lib/vident/attributes/typed.rb +27 -12
- data/lib/vident/base.rb +7 -5
- data/lib/vident/caching/cache_key.rb +1 -17
- data/lib/vident/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba2054320ceb13a2646f5f88f4dcef219ad4a5482118f1245472b07d8848f313
|
4
|
+
data.tar.gz: 7e0af03ee04bc52c6b7f35cd0da6490116428581bae587249380df7c71c8d863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cd4c1933065215f12d8640a4274164ddb869f9b013891f6ef569293b84dbcafea761c8442ebee81c0656c3c2d0e560f7d7ee4a36b5390cba2bc2148d5bc62b0
|
7
|
+
data.tar.gz: bd3549f2eaf0157bea9b8489c2fc9ea83f71d11afa998b6a013ef65ea86ff4f41cbb39caafb94b4ea5049c00b36e3be3a3b67c3cb9ec24020f842cda85476523
|
@@ -132,22 +132,28 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
132
132
|
|
133
133
|
def map_primitive_to_dry_type(signature, options, converter)
|
134
134
|
strict = !options[:convert]
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
signatures = extract_member_type_and_subclass(signature, options)
|
136
|
+
types = signatures.map do |type, subtype|
|
137
|
+
dry_type = dry_type_from_primary_type(type, strict, converter)
|
138
|
+
if subtype && dry_type.respond_to?(:of)
|
139
|
+
subtype_info = dry_type_from_primary_type(subtype, strict, converter)
|
140
|
+
# Sub types of collections currently can be nil - this should be an option
|
141
|
+
dry_type.of(subtype_info.optional.meta(required: false))
|
142
|
+
else
|
143
|
+
dry_type
|
144
|
+
end
|
143
145
|
end
|
146
|
+
types.reduce(:|)
|
144
147
|
end
|
145
148
|
|
146
149
|
def extract_member_type_and_subclass(signature, options)
|
147
|
-
|
148
|
-
|
150
|
+
case signature
|
151
|
+
when Set
|
152
|
+
signature.flat_map { |s| extract_member_type_and_subclass(s, options) }
|
153
|
+
when Array
|
154
|
+
[[Array, signature.first]]
|
149
155
|
else
|
150
|
-
[signature, options[:type] || options[:sub_type]]
|
156
|
+
[[signature, options[:type] || options[:sub_type]]]
|
151
157
|
end
|
152
158
|
end
|
153
159
|
|
@@ -185,7 +191,16 @@ if Gem.loaded_specs.has_key? "dry-struct"
|
|
185
191
|
# values using the default constructor, `new`.
|
186
192
|
Types.Instance(type)
|
187
193
|
else
|
188
|
-
|
194
|
+
# dry calls this when initialising the Type. Check if type of input is correct or coerce
|
195
|
+
Types.Constructor(type) do |value|
|
196
|
+
next value if value.is_a?(type)
|
197
|
+
|
198
|
+
if converter
|
199
|
+
converter.call(value)
|
200
|
+
else
|
201
|
+
type.new(**value)
|
202
|
+
end
|
203
|
+
end
|
189
204
|
end
|
190
205
|
end
|
191
206
|
end
|
data/lib/vident/base.rb
CHANGED
@@ -104,7 +104,12 @@ module Vident
|
|
104
104
|
else
|
105
105
|
RootComponent::UsingViewComponent
|
106
106
|
end
|
107
|
-
|
107
|
+
element_attrs = options
|
108
|
+
.except(:id, :element_tag, :html_options, :controller, :controllers, :actions, :targets, :named_classes, :data_maps)
|
109
|
+
.merge(
|
110
|
+
stimulus_options_for_component(options)
|
111
|
+
)
|
112
|
+
klass.new(**element_attrs)
|
108
113
|
end
|
109
114
|
end
|
110
115
|
alias_method :root, :parent_element
|
@@ -148,12 +153,11 @@ module Vident
|
|
148
153
|
end
|
149
154
|
module_function :stimulus_identifier_from_path
|
150
155
|
|
151
|
-
|
156
|
+
private
|
152
157
|
|
153
158
|
# Prepare the stimulus attributes for a StimulusComponent
|
154
159
|
def stimulus_options_for_component(options)
|
155
160
|
{
|
156
|
-
**options.except(:id, :element_tag, :html_options, :controller, :controllers, :actions, :targets, :named_classes, :data_maps),
|
157
161
|
id: respond_to?(:id) ? id : (attribute(:id) || options[:id]),
|
158
162
|
element_tag: attribute(:element_tag) || options[:element_tag] || :div,
|
159
163
|
html_options: prepare_html_options(options[:html_options]),
|
@@ -167,8 +171,6 @@ module Vident
|
|
167
171
|
}
|
168
172
|
end
|
169
173
|
|
170
|
-
private
|
171
|
-
|
172
174
|
def prepare_html_options(erb_options)
|
173
175
|
# Options should override in this order:
|
174
176
|
# - defined on component class methods (lowest priority)
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "benchmark"
|
4
|
-
|
5
3
|
# Rails fragment caching works by either expecting the cached key object to respond to `cache_key` or for that object
|
6
4
|
# to be an array or hash. In our case the object maybe an instance of Core::Presenter so here we add a default
|
7
5
|
# `cache_key` implementation.
|
@@ -26,10 +24,6 @@ module Vident
|
|
26
24
|
named_cache_key_includes(name, *attrs)
|
27
25
|
end
|
28
26
|
|
29
|
-
def enable_cache_key_benchmarking
|
30
|
-
@enable_cache_key_benchmarking = true
|
31
|
-
end
|
32
|
-
|
33
27
|
attr_reader :named_cache_key_attributes
|
34
28
|
|
35
29
|
# TypedComponents can be used with fragment caching, but you need to be careful! Read on...
|
@@ -100,17 +94,7 @@ module Vident
|
|
100
94
|
else
|
101
95
|
@cache_key ||= {}
|
102
96
|
end
|
103
|
-
|
104
|
-
# TODO: remove the benchmarking code here
|
105
|
-
|
106
|
-
if @enable_cache_key_benchmarking
|
107
|
-
time = ::Benchmark.measure { generate_cache_key(n) }
|
108
|
-
::Logging::Log.debug "Cache key #{self.class.name}: #{time.real}"
|
109
|
-
::Thread.current[:total_key_generation_time] ||= 0
|
110
|
-
::Thread.current[:total_key_generation_time] += time.real
|
111
|
-
else
|
112
|
-
generate_cache_key(n)
|
113
|
-
end
|
97
|
+
generate_cache_key(n)
|
114
98
|
@cache_key[n]
|
115
99
|
end
|
116
100
|
end
|
data/lib/vident/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|