stimulus_reflex_globalid 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4f8df309143cec5c46931b72c8dc81509e1363b13c0101212efc0ef6ae3b49a
4
+ data.tar.gz: c5d48bc64861e7d6c0574aac654c8d3dacf93ebb9625ea97832de177b8098e9b
5
+ SHA512:
6
+ metadata.gz: e8d3536d13316bfbca130563f64a47fac05e5ee3a71ad4e750501ec2a192203d64f89fcf88ec48e99ec77ece782dadcb2ea568fda3287b6ec007535af2c5898a
7
+ data.tar.gz: 81fc615d2e25c4e6f463344890ff82a4c6cee484f1926ad0aaac59cbe439f623add16077aaef49ee65704d945a675d23c7aa7dd809e0af2d8f6945e586ae305e
@@ -0,0 +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.
@@ -0,0 +1,31 @@
1
+ # StimulusReflexGlobalid
2
+
3
+ StimulusReflexGlobalId maps global IDs to instance variables during a reflex.
4
+
5
+ ## Installation
6
+ `bundle add stimulus_reflex_globalid`
7
+
8
+ ## Usage
9
+
10
+ No setup is required to use this library.
11
+
12
+ In your markup, specific data-reflex and data attributes as normal
13
+
14
+ ```erb
15
+ <button data-reflex="click->MyReflex#handle_click" data-foo="<%= @foo.to_global_id %>"
16
+ ```
17
+
18
+ When the button is clicked, an instance variable `@foo` will be created, set to `@foo`.
19
+
20
+ ```rb
21
+ class MyReflex < ApplicationReflex
22
+ def handle_click
23
+ p @foo
24
+ end
25
+ end
26
+ ```
27
+
28
+ You can also use signed IDs.
29
+
30
+ ## License
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
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 = 'StimulusReflexGlobalid'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ load 'rails/tasks/statistics.rake'
18
+
19
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ require "stimulus_reflex"
2
+ require "stimulus_reflex_globalid/engine"
3
+
4
+ module StimulusReflexGlobalid
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,23 @@
1
+ module StimulusReflexGlobalid
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace StimulusReflexGlobalid
4
+
5
+ config.to_prepare do
6
+ StimulusReflex::Reflex.class_eval do
7
+ alias_method :original_initialize, :initialize
8
+
9
+ unless instance_methods.include?(:original_initialize)
10
+ def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, permanent_attribute_name: nil, params: {})
11
+ original_initialize(channel, url: url, element: element, selectors: selectors, method_name: method_name, permanent_attribute_name: permanent_attribute_name, params: params)
12
+
13
+ @element.dataset.to_h.each do |k, v|
14
+ if (model = GlobalID::Locator.locate(v) || GlobalID::Locator.locate_signed(v))
15
+ instance_variable_set(:"@#{k}", model)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module StimulusReflexGlobalid
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stimulus_reflex_globalid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua LeBlanc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.3.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.3.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: stimulus_reflex
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Map global IDs to models in reflexes
62
+ email:
63
+ - joshleblanc94@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/stimulus_reflex_globalid.rb
72
+ - lib/stimulus_reflex_globalid/engine.rb
73
+ - lib/stimulus_reflex_globalid/version.rb
74
+ homepage: https://github.com/joshleblanc/stimulus_reflex_globalid
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Map global IDs to models in reflexes
98
+ test_files: []