view_component_reflex 3.0.2 → 3.0.6.pre.1

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: 9df2379bc1c256d8d3b703c542693300fd82af260540d819174e1ac77b98a42e
4
- data.tar.gz: 3918c1cbe4ef273c94583d65373a8a574971607e825769040a410282aed3558f
3
+ metadata.gz: aa816c40dd5218d794d19e5b41cc2328d0ed9b3f10e03f8e507001cacb96c627
4
+ data.tar.gz: ef1ad23aa5e1fae0cf0a8ee3a87af8a5d9179ee5f729554288c7a6811edfbdec
5
5
  SHA512:
6
- metadata.gz: c1c741bf5d6005a7cc8b9c48bf428b2920234872a7c5b2b186052c579f33448a5366f95d596e93e82e314d39dfe44086ae654d1aacb000ad764aabb5fc870a20
7
- data.tar.gz: 189253b1a19210ab6dfc550408300169bdd43b6ce42b69165286af86ee1bf1bff278c9bc65c97ee5d8513af946f68bcae10bd1ba67ea5f4bf0785e8d5db456c3
6
+ metadata.gz: 7ad4225e776e59d3fdeed3c7a37e59a614fabc1f4ef0c0982a8008d885d03faab21cefee30c3c5fb618a9dec57c3406525d405c62365056d2d04f368b88d6978
7
+ data.tar.gz: 67ae62aa96d3ee3ac4c309207434fc3324dc6d1d62f7e09561a0baad5bff497480be5c1b83c256451cabc617a82674242b25adf9074bcedbf8107d85954b0fa3
@@ -1,20 +1,20 @@
1
- Copyright 2020 Joshua LeBlanc
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2020 Joshua LeBlanc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,32 +1,32 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'ViewComponentReflex'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
- load 'rails/tasks/engine.rake'
19
-
20
- load 'rails/tasks/statistics.rake'
21
-
22
- require 'bundler/gem_tasks'
23
-
24
- require 'rake/testtask'
25
-
26
- Rake::TestTask.new(:test) do |t|
27
- t.libs << 'test'
28
- t.pattern = 'test/**/*_test.rb'
29
- t.verbose = false
30
- end
31
-
32
- task default: :test
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ViewComponentReflex'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -47,7 +47,7 @@ module ViewComponentReflex
47
47
  end
48
48
 
49
49
  def self.stimulus_controller
50
- name.chomp("Component").underscore.dasherize
50
+ name.chomp("Component").underscore.dasherize.gsub("/", "--")
51
51
  end
52
52
 
53
53
  def stimulus_reflex?
@@ -57,7 +57,7 @@ module ViewComponentReflex
57
57
  def component_controller(opts_or_tag = :div, opts = {}, &blk)
58
58
  init_key
59
59
 
60
- tag = :div
60
+ tag = :di
61
61
  options = if opts_or_tag.is_a? Hash
62
62
  opts_or_tag
63
63
  else
@@ -1,5 +1,6 @@
1
1
  require "stimulus_reflex"
2
2
  require 'view_component_reflex/reflex_factory'
3
+ require "view_component_reflex/state_adapter/base"
3
4
  require "view_component_reflex/state_adapter/session"
4
5
  require "view_component_reflex/state_adapter/memory"
5
6
  require "view_component_reflex/state_adapter/redis"
@@ -24,16 +24,7 @@ module ViewComponentReflex
24
24
  html: html.inner_html,
25
25
  children_only: true,
26
26
  permanent_attribute_name: "data-reflex-permanent",
27
- stimulus_reflex: {
28
- reflex_id: reflex_id,
29
- xpath: xpath,
30
- c_xpath: c_xpath,
31
- target: target,
32
- reflex_controller: reflex_controller,
33
- url: url,
34
- morph: :page,
35
- attrs: {key: element.dataset[:key]}
36
- }
27
+ stimulus_reflex: stimulus_reflex_data
37
28
  )
38
29
  end
39
30
  end
@@ -55,19 +46,25 @@ module ViewComponentReflex
55
46
  children_only: true,
56
47
  html: document.css(selector).inner_html,
57
48
  permanent_attribute_name: "data-reflex-permanent",
58
- stimulus_reflex: {
59
- reflex_id: reflex_id,
60
- xpath: xpath,
61
- target: target,
62
- c_xpath: c_xpath,
63
- reflex_controller: reflex_controller,
64
- url: url,
65
- morph: :page,
66
- attrs: {key: element.dataset[:key]}
67
- }
49
+ stimulus_reflex: stimulus_reflex_data
68
50
  )
69
51
  end
70
52
 
53
+ def stimulus_reflex_data
54
+ {
55
+ reflex_id: reflex_id,
56
+ xpath: xpath,
57
+ target: target,
58
+ c_xpath: c_xpath,
59
+ reflex_controller: reflex_controller,
60
+ url: url,
61
+ morph: :page,
62
+ attrs: {
63
+ key: element.dataset[:key]
64
+ }
65
+ }
66
+ end
67
+
71
68
  def target
72
69
  "#{component_class}##{method_name}"
73
70
  end
@@ -127,27 +124,49 @@ module ViewComponentReflex
127
124
  end
128
125
 
129
126
  def stimulate(target, data)
130
- dataset = {}
131
- data.each do |k, v|
132
- dataset["data-#{k}"] = v.to_s
127
+ data_to_receive = {}
128
+
129
+ stimulus_reflex_data.each do |k, v|
130
+ data_to_receive[k.to_s.camelize(:lower)] = v
131
+ end
132
+
133
+ data_to_receive["dataset"] = data.each_with_object({}) do |(k, v), o|
134
+ o["data-#{k}"] = v
133
135
  end
134
- channel.receive({
135
- "target" => target,
136
- "attrs" => element.attributes.to_h.symbolize_keys,
137
- "dataset" => dataset
138
- })
136
+
137
+ data_to_receive["attrs"] = element.attributes.to_h.symbolize_keys
138
+ data_to_receive["target"] = target
139
+
140
+ channel.receive data_to_receive
139
141
  end
140
142
 
141
143
  def component
142
144
  return @component if @component
143
145
  @component = component_class.allocate
144
146
  reflex = self
145
- exposed_methods = [:params, :request, :connection, :element, :refresh!, :refresh_all!, :stimulus_controller, :session, :prevent_refresh!, :selector, :stimulate]
147
+ exposed_methods = [
148
+ :params,
149
+ :request,
150
+ :connection,
151
+ :element,
152
+ :refresh!,
153
+ :refresh_all!,
154
+ :stimulus_controller,
155
+ :session,
156
+ :prevent_refresh!,
157
+ :selector,
158
+ :stimulate
159
+ ]
146
160
  exposed_methods.each do |meth|
147
161
  @component.define_singleton_method(meth) do |*a|
148
162
  reflex.send(meth, *a)
149
163
  end
150
164
  end
165
+
166
+ @component.define_singleton_method(:reflex) do
167
+ reflex
168
+ end
169
+
151
170
  @component
152
171
  end
153
172
 
@@ -0,0 +1,18 @@
1
+ module ViewComponentReflex
2
+ module StateAdapter
3
+ class Base
4
+
5
+ private
6
+
7
+ def self.extract_id(request)
8
+ session = request&.session
9
+ if session.respond_to? :id
10
+ session.id.to_s
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  VIEW_COMPONENT_REFLEX_MEMORY_STATE = {}
2
2
  module ViewComponentReflex
3
3
  module StateAdapter
4
- class Memory
4
+ class Memory < Base
5
5
  def self.state(request, key)
6
6
  id = extract_id(request)
7
7
 
@@ -28,17 +28,6 @@ module ViewComponentReflex
28
28
  def self.wrap_write_async
29
29
  yield
30
30
  end
31
-
32
- private
33
-
34
- def self.extract_id(request)
35
- session = request&.session
36
- if session.respond_to? :id
37
- session.id.to_s
38
- else
39
- nil
40
- end
41
- end
42
31
  end
43
32
  end
44
33
  end
@@ -10,7 +10,7 @@
10
10
 
11
11
  module ViewComponentReflex
12
12
  module StateAdapter
13
- class Redis
13
+ class Redis < Base
14
14
  attr_reader :client, :ttl
15
15
 
16
16
  def initialize(redis_opts:, ttl: 3600)
@@ -67,8 +67,9 @@ module ViewComponentReflex
67
67
  end
68
68
 
69
69
  def get_key(request, key)
70
- "#{request.session.id.to_s}_#{key}_session_reflex_redis"
70
+ id = Redis.extract_id(request)
71
+ "#{id}_#{key}_session_reflex_redis"
71
72
  end
72
73
  end
73
74
  end
74
- end
75
+ end
@@ -1,6 +1,6 @@
1
1
  module ViewComponentReflex
2
2
  module StateAdapter
3
- class Session
3
+ class Session < Base
4
4
  def self.state(request, key)
5
5
  request.session[key] ||= {}
6
6
  end
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '3.0.2'
2
+ VERSION = '3.0.6.pre.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.6.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua LeBlanc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: stimulus_reflex
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.4.0.pre9
39
+ version: 3.4.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 3.4.0.pre9
46
+ version: 3.4.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: view_component
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +87,7 @@ files:
87
87
  - lib/view_component_reflex/engine.rb
88
88
  - lib/view_component_reflex/reflex.rb
89
89
  - lib/view_component_reflex/reflex_factory.rb
90
+ - lib/view_component_reflex/state_adapter/base.rb
90
91
  - lib/view_component_reflex/state_adapter/memory.rb
91
92
  - lib/view_component_reflex/state_adapter/redis.rb
92
93
  - lib/view_component_reflex/state_adapter/session.rb
@@ -96,7 +97,7 @@ licenses:
96
97
  - MIT
97
98
  metadata:
98
99
  allowed_push_host: https://rubygems.org
99
- post_install_message:
100
+ post_install_message:
100
101
  rdoc_options: []
101
102
  require_paths:
102
103
  - lib
@@ -107,12 +108,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  required_rubygems_version: !ruby/object:Gem::Requirement
109
110
  requirements:
110
- - - ">="
111
+ - - ">"
111
112
  - !ruby/object:Gem::Version
112
- version: '0'
113
+ version: 1.3.1
113
114
  requirements: []
114
- rubygems_version: 3.1.4
115
- signing_key:
115
+ rubygems_version: 3.0.3
116
+ signing_key:
116
117
  specification_version: 4
117
118
  summary: Allow stimulus reflexes in a view component
118
119
  test_files: []