referehencible 1.1.0 → 1.1.3

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
- SHA1:
3
- metadata.gz: 5dfa1b825abed0a534976e50febde7707f2a3e44
4
- data.tar.gz: 285f4e461dd1f13e292b864bb68c304bfbc83033
2
+ SHA256:
3
+ metadata.gz: b47ff65b25afe262a8353dd4caf94be08bb0b2fb0595cc1e967bdbad96216366
4
+ data.tar.gz: 920d2def13bb813573d44d7ed53983e91eb0bbce07afc3e899aab6c776116151
5
5
  SHA512:
6
- metadata.gz: 46683349d3fd53d5aee7b8739a085054a1391279549dae06f47a5c4140f73aae6fe5a7772adeedd724429a69857908d57fe6a1583971b5555c41d19e2dd2ba20
7
- data.tar.gz: 8e72ea6c2afe7d433fd545f4477a19235bbc40d3acbd9a843a681b17953b26f63b30453a2b17a298d7983cad815b45becce380e0f08d1f24f76c05b2bd5687c9
6
+ metadata.gz: d38f5ce476b12bf4c8c333e127567ddcd1823f3005b40150068405fa7e6d8b70109e0189c66c52de327521af3b7c76cdd7807d96007459ce05b04c31c4896d24
7
+ data.tar.gz: 20a51c7c6d6143360ec9b31c6d1041fd3a3fcd736117530e1c51ab5ff436ed4f40adc21753bec940139d0cedd22161feecb4c3ebb1504f2b2542cfd6d355bece
checksums.yaml.gz.sig ADDED
Binary file
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010-2016 The Kompanee, Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Referehencible
2
- VERSION = '1.1.0'
4
+ VERSION = '1.1.3'
3
5
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'referehencible/version'
2
4
  require 'securerandom'
3
5
 
6
+ # rubocop:disable Metrics/LineLength, Metrics/PerceivedComplexity
4
7
  module Referehencible
5
8
  DEFAULT_LENGTH = 36
6
9
 
@@ -12,69 +15,86 @@ module Referehencible
12
15
  type: :uuid,
13
16
  }
14
17
 
15
- referenced_attrs = \
16
- referenced_attrs.each_with_object({}) do |referenced_attr, transformed_attr|
17
- case referenced_attr
18
- when Symbol
19
- transformed_attr[referenced_attr] = default_options
20
- when Hash
21
- transformed_attr.merge! referenced_attr
22
- end
18
+ referenced_attrs = referenced_attrs.each_with_object({}) do |referenced_attr, transformed_attr|
19
+ case referenced_attr
20
+ when Symbol
21
+ transformed_attr[referenced_attr] = default_options
22
+ when Hash
23
+ transformed_attr.merge! referenced_attr
23
24
  end
25
+ end
24
26
 
25
27
  referenced_attrs.each do |reference_attribute, options|
26
- validates reference_attribute,
27
- presence: true,
28
- uniqueness: true,
29
- format: {
30
- with: /[a-f0-9\-]{#{options[:length]}}/ },
31
- length: {
32
- is: options[:length] }
28
+ if respond_to?(:validates)
29
+ validates reference_attribute,
30
+ presence: true,
31
+ format: {
32
+ with: /[a-zA-Z0-9\-_=]{#{options[:length]}}/,
33
+ },
34
+ length: {
35
+ is: options[:length],
36
+ }
37
+ end
33
38
 
34
39
  define_method(reference_attribute) do
35
- send("generate_#{options[:type]}_guid",
36
- reference_attribute,
37
- options[:length])
40
+ read_reference_attribute(reference_attribute) ||
41
+ write_reference_attribute(reference_attribute, __send__("generate_#{options[:type]}_guid", options[:length]))
38
42
  end
39
43
 
40
- define_singleton_method("by_#{reference_attribute}") do |guid_to_find|
41
- where(:"#{reference_attribute}" => guid_to_find).
42
- first ||
44
+ define_singleton_method("for_#{reference_attribute}") do |guid_to_find|
45
+ where("#{reference_attribute}": guid_to_find)
46
+ end
47
+
48
+ define_singleton_method("find_for_#{reference_attribute}") do |guid_to_find|
49
+ where("#{reference_attribute}": guid_to_find).first ||
43
50
  unknown_reference_object
44
51
  end
45
52
 
53
+ next unless respond_to?(:after_initialize)
54
+
46
55
  after_initialize(lambda do
47
- send("generate_#{options[:type]}_guid",
48
- reference_attribute,
49
- options[:length])
56
+ __send__("generate_#{options[:type]}_guid",
57
+ reference_attribute,
58
+ options[:length])
50
59
  end)
51
60
  end
52
61
 
53
- private
62
+ define_method(:generate_hex_guid) do |length|
63
+ hex_length = ((length / 2.0) + 1).floor
54
64
 
55
- define_method(:generate_hex_guid) do |reference_attribute, length|
56
- hex_length = (length / 2.0 + 1).floor
65
+ SecureRandom.hex(hex_length).slice(0, length)
66
+ end
57
67
 
58
- read_attribute(reference_attribute) ||
59
- write_attribute(reference_attribute,
60
- SecureRandom.hex(hex_length).slice(0, length))
68
+ define_method(:generate_base64_guid) do |length|
69
+ SecureRandom.urlsafe_base64(length).slice(0, length)
61
70
  end
62
71
 
63
- define_method(:generate_base64_guid) do |reference_attribute, length|
64
- read_attribute(reference_attribute) ||
65
- write_attribute(reference_attribute,
66
- SecureRandom.urlsafe_base64(length).slice(0, length))
72
+ define_method(:generate_uuid_guid) do |_length|
73
+ SecureRandom.uuid
67
74
  end
68
75
 
69
- define_method(:generate_uuid_guid) do |reference_attribute, _length|
70
- read_attribute(reference_attribute) || write_attribute(reference_attribute,
71
- SecureRandom.uuid)
76
+ define_method(:read_reference_attribute) do |reference_attribute|
77
+ if respond_to?(:read_attribute)
78
+ read_attribute(reference_attribute)
79
+ else
80
+ instance_variable_get("@#{reference_attribute}")
81
+ end
72
82
  end
73
83
 
74
- define_singleton_method(:unknown_reference_object) do
75
- return new unless respond_to?(:as_null_object)
84
+ define_method(:write_reference_attribute) do |reference_attribute, value|
85
+ if respond_to?(:write_attribute)
86
+ write_attribute(reference_attribute, value)
87
+ else
88
+ instance_variable_set("@#{reference_attribute}", value)
89
+ end
90
+ end
76
91
 
77
- as_null_object
92
+ define_singleton_method(:unknown_reference_object) do
93
+ if respond_to?(:as_null_object)
94
+ as_null_object
95
+ else
96
+ new
97
+ end
78
98
  end
79
99
  end
80
100
  end
@@ -84,3 +104,4 @@ module Referehencible
84
104
  base.extend ClassMethods
85
105
  end
86
106
  end
107
+ # rubocop:enable Metrics/LineLength, Metrics/PerceivedComplexity
@@ -1,7 +1,6 @@
1
- require 'rspectacular'
1
+ # frozen_string_literal: true
2
2
 
3
- class Referenced
4
- end
3
+ require 'rspectacular'
5
4
 
6
5
  # describe Referehencible do
7
6
  # it { expect(subject).to allow_value('a' * 32).for :guid }
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���l�Ϋ2���g=zo+�����(4W�(���z����K�%i�'�@&g?�E�A�[NF_�j��@+a%��<2Nr��}'��Z���p�j�J��K���C)
2
+ ���#J����]�B��̃�׫�����_����G2�O�XdQ���� �S>(����d�x}�������
metadata CHANGED
@@ -1,14 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: referehencible
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEdjCCAt6gAwIBAgIBATANBgkqhkiG9w0BAQsFADAyMTAwLgYDVQQDDCdhY2Nv
14
+ dW50c19ydWJ5Z2Vtcy9EQz10aGVrb21wYW5lZS9EQz1jb20wHhcNMjIwNzMxMDYz
15
+ MjI4WhcNMjMwNzMxMDYzMjI4WjAyMTAwLgYDVQQDDCdhY2NvdW50c19ydWJ5Z2Vt
16
+ cy9EQz10aGVrb21wYW5lZS9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw
17
+ ggGKAoIBgQD0Z84PxtE0iiWCMTQbnit6D4w55GGBQZnhpWUCJwC0SpQ/jnT0Fsma
18
+ g8oAIdDclLvLC9jzqSAmkOujlpkJMb5NabgkhKFwHi6cVW/gz/cVnISAv8LQTIM5
19
+ c1wyhwX/YhVFaNYNzMizB//kZOeXnv6x0tqV9NY7urHcT6mCwyLeNJIgf44i1Ut+
20
+ mKtXxEyXNbfWQLVY95bVoVg3GOCkycerZN4Oh3zSJM1s+cZRBFlg7GR1AE3Xqs6k
21
+ RhE7yp8ufeghC3bbxgnQrkk8W8Fkkl0/+2JAENpdE4OUepC6dFzDlLZ3UvSk7VHf
22
+ NBRKSuO15kpPo2G55N0HLy8abUzbu5cqjhSbIk9hzD6AmdGCT4DqlsdHI5gOrGP0
23
+ BO6VxGpRuRETKoZ4epPCsXC2XAwk3TJXkuuqYkgdcv8ZR4rPW2CiPvRqgG1YVwWj
24
+ SrIy5Dt/dlMvxdIMiTj6ytAQP1kfdKPFWrJTIA2tspl/eNB+LiYsVdj8d0UU/KTY
25
+ y7jqKMpOE1UCAwEAAaOBljCBkzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
26
+ HQ4EFgQU7+XQuN042fZGvzLhYbIwDfsxZV8wLAYDVR0RBCUwI4EhYWNjb3VudHMr
27
+ cnVieWdlbXNAdGhla29tcGFuZWUuY29tMCwGA1UdEgQlMCOBIWFjY291bnRzK3J1
28
+ YnlnZW1zQHRoZWtvbXBhbmVlLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAqSCjcA7/
29
+ 0KcSMDbd2A18PkL6KhN5yzegFSrYjPRBXafeeeDL1PNhHhhRXfFQ1DcWiAmyhh8t
30
+ 1k51qMNRnaloWsUMfKLOAcKInWO9KeztNBac4T/6GzyaMCQgTJIv9LkrZUX/eUJ3
31
+ VMMv9NA126ZeN26jgkthYtjFoP9WRQTN3uErzDa+gHFolgo4LI9Nia5A7YWWP1+N
32
+ AivOEW51EmYvE8Ud8Z+NW2vD++Sk1ZQzuzuRGqIa5YelKfwp4KgGGYZGSgQZpB10
33
+ 1JiW5aLu5IApKKWGhDEUUgn/+iXtgftjSfkAw8afTL71NMUHXBnXrA+54tj628+o
34
+ 98Qb5iJMLjWXsp/2OcdkktHX68UUkVlllHCLDfHEy+tqmmXSpGs0sOqh6rb/TTvj
35
+ aZLh8zmkRmtdlDjYgMJe0A2UykqfjF/uf9Rd+bessKZhGsgu5SSbN9GL1apGWxTN
36
+ Y2DRAv7nrHlYPwc8cDRNbts6xgesS8w1VCSoujECs1i/UsrXT28g0AXg
37
+ -----END CERTIFICATE-----
38
+ date: 2022-07-31 00:00:00.000000000 Z
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rspec
@@ -42,22 +69,21 @@ description: ''
42
69
  email: accounts+git@thekompanee.com
43
70
  executables: []
44
71
  extensions: []
45
- extra_rdoc_files:
46
- - README.md
47
- - LICENSE
72
+ extra_rdoc_files: []
48
73
  files:
49
- - LICENSE
74
+ - LICENSE.txt
50
75
  - README.md
51
76
  - Rakefile
52
77
  - lib/referehencible.rb
53
78
  - lib/referehencible/version.rb
54
79
  - spec/lib/referehencible_spec.rb
55
80
  homepage: https://github.com/chirrpy/referehencible
56
- licenses: []
57
- metadata: {}
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ allowed_push_host: https://rubygems.org
58
85
  post_install_message:
59
- rdoc_options:
60
- - "--charset = UTF-8"
86
+ rdoc_options: []
61
87
  require_paths:
62
88
  - lib
63
89
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -71,11 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
97
  - !ruby/object:Gem::Version
72
98
  version: '0'
73
99
  requirements: []
74
- rubyforge_project: referehencible
75
- rubygems_version: 2.4.5
100
+ rubygems_version: 3.1.6
76
101
  signing_key:
77
102
  specification_version: 4
78
103
  summary: Enable unique reference numbers on all the things
79
104
  test_files:
80
105
  - spec/lib/referehencible_spec.rb
81
- has_rdoc:
metadata.gz.sig ADDED
Binary file
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Jeff Felchner
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.