futurism 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/futurism/channel.rb +5 -1
- data/lib/futurism/channel.rb~ +15 -3
- data/lib/futurism/helpers.rb +9 -1
- data/lib/futurism/helpers.rb~ +19 -9
- data/lib/futurism/shims/deep_transform_values.rb +47 -0
- data/lib/futurism/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cde59cb75363c7ba6032575a5783a0f0407cdb630fa1301fda0c38e7bc21949f
|
4
|
+
data.tar.gz: d8f5acd7d125dd0b41071704c10e0db6cca741cea7f271c290517527ff522ef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d561d2864614bbc0bc41f030477f7cc1ab8ea3518edbca35903054adcc0107aad3634085cd3de85455f2c0d0569829a13ec7cb2ada161db812b478d2140cd2
|
7
|
+
data.tar.gz: efcd9f32c2814e05f9603daf8e949c6df2869d32e94da772cf6097ceb6e5587f3d543363c95eea07f8ad26e41ce18430899a6e2a541bff31ccc0c62cb1171883
|
data/lib/futurism/channel.rb
CHANGED
@@ -37,7 +37,11 @@ module Futurism
|
|
37
37
|
def resource(signed_params:, sgid:)
|
38
38
|
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
39
39
|
|
40
|
-
Rails
|
40
|
+
Rails
|
41
|
+
.application
|
42
|
+
.message_verifier("futurism")
|
43
|
+
.verify(signed_params)
|
44
|
+
.deep_transform_values { |value| value.is_a?(String) && value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
data/lib/futurism/channel.rb~
CHANGED
@@ -2,8 +2,16 @@ module Futurism
|
|
2
2
|
class Channel < ActionCable::Channel::Base
|
3
3
|
include CableReady::Broadcaster
|
4
4
|
|
5
|
+
def stream_name
|
6
|
+
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) || send(identifier) }
|
7
|
+
[
|
8
|
+
params[:channel],
|
9
|
+
ids.select(&:present?).join(";")
|
10
|
+
].select(&:present?).join(":")
|
11
|
+
end
|
12
|
+
|
5
13
|
def subscribed
|
6
|
-
stream_from
|
14
|
+
stream_from stream_name
|
7
15
|
end
|
8
16
|
|
9
17
|
def receive(data)
|
@@ -15,7 +23,7 @@ module Futurism
|
|
15
23
|
resources.each do |signed_params, sgid|
|
16
24
|
selector = "[data-signed-params='#{signed_params}']"
|
17
25
|
selector << "[data-sgid='#{sgid}']" if sgid.present?
|
18
|
-
cable_ready[
|
26
|
+
cable_ready[stream_name].outer_html(
|
19
27
|
selector: selector,
|
20
28
|
html: ApplicationController.render(resource(signed_params: signed_params, sgid: sgid))
|
21
29
|
)
|
@@ -29,7 +37,11 @@ module Futurism
|
|
29
37
|
def resource(signed_params:, sgid:)
|
30
38
|
return GlobalID::Locator.locate_signed(sgid) if sgid.present?
|
31
39
|
|
32
|
-
Rails
|
40
|
+
Rails
|
41
|
+
.application
|
42
|
+
.message_verifier("futurism")
|
43
|
+
.verify(signed_params)
|
44
|
+
.deep_transform_values { |value| value.start_with?("gid://") ? GlobalID::Locator.locate(value) : value }
|
33
45
|
end
|
34
46
|
end
|
35
47
|
end
|
data/lib/futurism/helpers.rb
CHANGED
@@ -65,10 +65,18 @@ module Futurism
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
def transformed_options
|
69
|
+
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
|
+
|
71
|
+
options.deep_transform_values do |value|
|
72
|
+
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
68
76
|
private
|
69
77
|
|
70
78
|
def signed_params
|
71
|
-
Rails.application.message_verifier("futurism").generate(
|
79
|
+
Rails.application.message_verifier("futurism").generate(transformed_options)
|
72
80
|
end
|
73
81
|
end
|
74
82
|
end
|
data/lib/futurism/helpers.rb~
CHANGED
@@ -6,7 +6,8 @@ module Futurism
|
|
6
6
|
if records_or_string.is_a?(ActiveRecord::Base) || records_or_string.is_a?(ActiveRecord::Relation)
|
7
7
|
futurize_active_record(records_or_string, extends: extends, placeholder: placeholder, **options)
|
8
8
|
elsif records_or_string.is_a?(String)
|
9
|
-
|
9
|
+
html_options = options.delete(:html_options)
|
10
|
+
futurize_with_options(extends: extends, placeholder: placeholder, partial: records_or_string, locals: options, html_options: html_options)
|
10
11
|
else
|
11
12
|
futurize_with_options(extends: extends, placeholder: placeholder, **options)
|
12
13
|
end
|
@@ -35,38 +36,47 @@ module Futurism
|
|
35
36
|
class Element
|
36
37
|
include ActionView::Helpers
|
37
38
|
|
38
|
-
attr_reader :extends, :placeholder, :html_options, :model, :options
|
39
|
+
attr_reader :extends, :placeholder, :html_options, :data_attributes, :model, :options
|
39
40
|
|
40
41
|
def initialize(extends:, placeholder:, options:)
|
41
42
|
@extends = extends
|
42
43
|
@placeholder = placeholder
|
43
44
|
@html_options = options.delete(:html_options) || {}
|
45
|
+
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params)
|
44
46
|
@model = options.delete(:model)
|
45
|
-
@options = options
|
47
|
+
@options = data_attributes.any? ? options.merge(data: data_attributes) : options
|
46
48
|
end
|
47
49
|
|
48
50
|
def dataset
|
49
|
-
{
|
51
|
+
data_attributes.merge({
|
50
52
|
signed_params: signed_params,
|
51
53
|
sgid: model && model.to_sgid.to_s
|
52
|
-
}
|
54
|
+
})
|
53
55
|
end
|
54
56
|
|
55
57
|
def render
|
56
58
|
case extends
|
57
59
|
when :li
|
58
|
-
content_tag :li, placeholder, {data: dataset, is: "futurism-li"}
|
60
|
+
content_tag :li, placeholder, html_options.deep_merge({data: dataset, is: "futurism-li"})
|
59
61
|
when :tr
|
60
|
-
content_tag :tr, placeholder, {data: dataset, is: "futurism-table-row"}
|
62
|
+
content_tag :tr, placeholder, html_options.deep_merge({data: dataset, is: "futurism-table-row"})
|
61
63
|
else
|
62
|
-
content_tag :"futurism-element", placeholder, {data: dataset}
|
64
|
+
content_tag :"futurism-element", placeholder, html_options.deep_merge({data: dataset})
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def transformed_options
|
69
|
+
require_relative "shims/deep_transform_values" unless options.respond_to? :deep_transform_values
|
70
|
+
|
71
|
+
options.deep_transform_values do |value|
|
72
|
+
value.is_a?(ActiveRecord::Base) ? value.to_global_id.to_s : value
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
66
76
|
private
|
67
77
|
|
68
78
|
def signed_params
|
69
|
-
Rails.application.message_verifier("futurism").generate(
|
79
|
+
Rails.application.message_verifier("futurism").generate(transformed_options)
|
70
80
|
end
|
71
81
|
end
|
72
82
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with all values converted by the block operation.
|
5
|
+
# This includes the values from the root hash and from all
|
6
|
+
# nested hashes and arrays.
|
7
|
+
#
|
8
|
+
# hash = { person: { name: 'Rob', age: '28' } }
|
9
|
+
#
|
10
|
+
# hash.deep_transform_values{ |value| value.to_s.upcase }
|
11
|
+
# # => {person: {name: "ROB", age: "28"}}
|
12
|
+
def deep_transform_values(&block)
|
13
|
+
_deep_transform_values_in_object(self, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Destructively converts all values by using the block operation.
|
17
|
+
# This includes the values from the root hash and from all
|
18
|
+
# nested hashes and arrays.
|
19
|
+
def deep_transform_values!(&block)
|
20
|
+
_deep_transform_values_in_object!(self, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Support methods for deep transforming nested hashes and arrays.
|
26
|
+
def _deep_transform_values_in_object(object, &block)
|
27
|
+
case object
|
28
|
+
when Hash
|
29
|
+
object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
|
30
|
+
when Array
|
31
|
+
object.map { |e| _deep_transform_values_in_object(e, &block) }
|
32
|
+
else
|
33
|
+
yield(object)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def _deep_transform_values_in_object!(object, &block)
|
38
|
+
case object
|
39
|
+
when Hash
|
40
|
+
object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) }
|
41
|
+
when Array
|
42
|
+
object.map! { |e| _deep_transform_values_in_object!(e, &block) }
|
43
|
+
else
|
44
|
+
yield(object)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/futurism/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: futurism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +142,14 @@ dependencies:
|
|
128
142
|
requirements:
|
129
143
|
- - ">="
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '5.2'
|
132
146
|
type: :runtime
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '5.2'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: cable_ready
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +184,7 @@ files:
|
|
170
184
|
- lib/futurism/engine.rb
|
171
185
|
- lib/futurism/helpers.rb
|
172
186
|
- lib/futurism/helpers.rb~
|
187
|
+
- lib/futurism/shims/deep_transform_values.rb
|
173
188
|
- lib/futurism/version.rb
|
174
189
|
- lib/tasks/futurism_tasks.rake
|
175
190
|
- lib/tasks/futurism_tasks.rake~
|