stimulus_reflex_globalid 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79d6c20e85adb18010b093e683a32469c35d9b949bd4c8071ee506549f2db7e8
4
- data.tar.gz: b0b0e42f637f19ec2d13121514e77bdf3d97ad1392326a0d03957e9e7084040b
3
+ metadata.gz: dd88a9b7294e63992aa8bdb41e10e6f826e97ae52d22e75cae13c0e81eb16a8e
4
+ data.tar.gz: dd36e583e959ecc490adc8304737716bfc7bf3dacc3433eb25a6c2c61ceba82b
5
5
  SHA512:
6
- metadata.gz: ddd68afae7f873e2b916177e452301d78decdff8362bb2d4136575d957dfca392307a9963a38c9de07d9822dcf291f07a188296e13e8aa4ccca4944d319593ae
7
- data.tar.gz: 138f96cdd67bdd2114adad1644d1921196bd8936eea871fe9ed0bb00f75cfee413f1f6ed6f74adbe88143a80a1fed1b4402ff7db7745560fd2bb86bdcbedfde3
6
+ metadata.gz: ecd8f0a88abab31b368cc2c4f48171b7c19d1cd7cc2eb2c34f00c2a456321c38ccfccacbe326e8f117c3904cfc9b35dab6a23921542a6e222450f760bd77a79f
7
+ data.tar.gz: ef72769f8eb3ce52a13e4c680807f0b3892beaf3274a46248dc7a09cd5e3ef7fb92c85783397b095dd17429c0b757df60557428054f62c2d4bc50da97a13bc83
data/README.md CHANGED
@@ -27,5 +27,16 @@ end
27
27
 
28
28
  You can also use signed IDs.
29
29
 
30
+ ## Configuring
31
+
32
+ You can turn off signed/unsigned IDs by configuring the gem.
33
+
34
+ ```
35
+ StimulusReflexGlobalid::Engine.configure do |config|
36
+ config.allow_signed = false # default true
37
+ config.allow_unsigned = false # default true
38
+ end
39
+ ```
40
+
30
41
  ## License
31
42
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,6 +2,14 @@ module StimulusReflexGlobalid
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace StimulusReflexGlobalid
4
4
 
5
+ class << self
6
+ mattr_accessor :allow_signed
7
+ mattr_accessor :allow_unsigned
8
+
9
+ self.allow_signed = true
10
+ self.allow_signed = true
11
+ end
12
+
5
13
  @monkey_patched = false
6
14
  config.to_prepare do
7
15
  StimulusReflex::Reflex.class_eval do
@@ -15,13 +23,20 @@ module StimulusReflexGlobalid
15
23
  original_initialize(channel, url: url, element: element, selectors: selectors, method_name: method_name, permanent_attribute_name: permanent_attribute_name, params: params)
16
24
 
17
25
  @element.dataset.to_h.each do |k, v|
18
- if (model = GlobalID::Locator.locate(v) || GlobalID::Locator.locate_signed(v))
19
- instance_variable_set(:"@#{k}", model)
20
- end
26
+ model = nil
27
+
28
+ model = GlobalID::Locator.locate(v) if StimulusReflexGlobalid::Engine.allow_unsigned
29
+ model = GlobalID::Locator.locate_signed(v) if StimulusReflexGlobalid::Engine.allow_signed && !model
30
+
31
+ instance_variable_set(:"@#{k}", model) if model
21
32
  end
22
33
  end
23
34
  end
24
35
  end
25
36
  end
37
+
38
+ def self.configure
39
+ yield self if block_given?
40
+ end
26
41
  end
27
42
  end
@@ -1,3 +1,3 @@
1
1
  module StimulusReflexGlobalid
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_reflex_globalid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua LeBlanc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-15 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails