referehencible 1.1.1 → 1.1.2

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
  SHA1:
3
- metadata.gz: 88d6869752b39859738c94984faee27783357cc9
4
- data.tar.gz: e387f77a4a07041bc5eeb73110a909f378b4c29e
3
+ metadata.gz: 08c3273923b9c5c8b8f3645c026096cc0a8a9e88
4
+ data.tar.gz: d03cd8b1e397086a66d49789a43fd54a05aa58cf
5
5
  SHA512:
6
- metadata.gz: 666f1337da2bf16bef4e4c61df6fa87946a20878cc99a3cc2efff77303d6f72260195f204ac2193bf0a31f9bb12f32da730d82a5a3491bc22f3b92fc3857cb18
7
- data.tar.gz: 84b3a0cd926dc58d48fad689b0c840339b174cb5c03849a2669e8988ae040426201caa74c1a353396be446fd3883c6ace718ac839e94f91ea55c6897bba07e8c
6
+ metadata.gz: a490469c9c6a56902b6e46d081304defa68db2ba18a1f55a2d75a723d1fffd26829cc72e1dc6d3c5debc8e1148d4eba399f3b8c7dc6cdb0d571014732ae8dfc0
7
+ data.tar.gz: 770a5ac3a5ac21bc882803374a5cdd07321d325f1a3d82c1248c582377fcc1b0d0e2f9b6c070cad9416dc9737b4d69601bb3cd6bb4a980c7bdbd62242358efae
Binary file
Binary file
@@ -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.
@@ -1,6 +1,9 @@
1
1
  require 'referehencible/version'
2
2
  require 'securerandom'
3
3
 
4
+ # rubocop:disable Metrics/LineLength, Metrics/PerceivedComplexity
5
+ # :reek:DuplicateMethodCall
6
+ # :reek:NestedIterators
4
7
  module Referehencible
5
8
  DEFAULT_LENGTH = 36
6
9
 
@@ -12,69 +15,87 @@ module Referehencible
12
15
  type: :uuid,
13
16
  }
14
17
 
15
- referenced_attrs = \
16
- referenced_attrs.each_with_object({}) do |referenced_attr, transformed_attr|
18
+ referenced_attrs = referenced_attrs.each_with_object({}) do |referenced_attr, transformed_attr|
17
19
  case referenced_attr
18
20
  when Symbol
19
21
  transformed_attr[referenced_attr] = default_options
20
22
  when Hash
21
23
  transformed_attr.merge! referenced_attr
22
24
  end
23
- 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-zA-Z0-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)
46
54
  after_initialize(lambda do
47
- send("generate_#{options[:type]}_guid",
48
- reference_attribute,
49
- options[:length])
55
+ __send__("generate_#{options[:type]}_guid",
56
+ reference_attribute,
57
+ options[:length])
50
58
  end)
51
59
  end
52
60
 
53
61
  private
54
62
 
55
- define_method(:generate_hex_guid) do |reference_attribute, length|
63
+ define_method(:generate_hex_guid) do |length|
56
64
  hex_length = (length / 2.0 + 1).floor
57
65
 
58
- read_attribute(reference_attribute) ||
59
- write_attribute(reference_attribute,
60
- SecureRandom.hex(hex_length).slice(0, length))
66
+ SecureRandom.hex(hex_length).slice(0, length)
61
67
  end
62
68
 
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))
69
+ define_method(:generate_base64_guid) do |length|
70
+ SecureRandom.urlsafe_base64(length).slice(0, length)
67
71
  end
68
72
 
69
- define_method(:generate_uuid_guid) do |reference_attribute, _length|
70
- read_attribute(reference_attribute) || write_attribute(reference_attribute,
71
- SecureRandom.uuid)
73
+ define_method(:generate_uuid_guid) do |_length|
74
+ SecureRandom.uuid
72
75
  end
73
76
 
74
- define_singleton_method(:unknown_reference_object) do
75
- return new unless respond_to?(:as_null_object)
77
+ define_method(:read_reference_attribute) do |reference_attribute|
78
+ if respond_to?(:read_attribute)
79
+ read_attribute(reference_attribute)
80
+ else
81
+ instance_variable_get("@#{reference_attribute}")
82
+ end
83
+ end
84
+
85
+ define_method(:write_reference_attribute) do |reference_attribute, value|
86
+ if respond_to?(:write_attribute)
87
+ write_attribute(reference_attribute, value)
88
+ else
89
+ instance_variable_set("@#{reference_attribute}", value)
90
+ end
91
+ end
76
92
 
77
- as_null_object
93
+ define_singleton_method(:unknown_reference_object) do
94
+ if respond_to?(:as_null_object)
95
+ as_null_object
96
+ else
97
+ new
98
+ end
78
99
  end
79
100
  end
80
101
  end
@@ -84,3 +105,4 @@ module Referehencible
84
105
  base.extend ClassMethods
85
106
  end
86
107
  end
108
+ # rubocop:enable Metrics/LineLength, Metrics/PerceivedComplexity
@@ -1,3 +1,3 @@
1
1
  module Referehencible
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: referehencible
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
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
+ MIIDrjCCApagAwIBAgIBATANBgkqhkiG9w0BAQUFADBOMRowGAYDVQQDDBFhY2Nv
14
+ dW50c19ydWJ5Z2VtczEbMBkGCgmSJomT8ixkARkWC3RoZWtvbXBhbmVlMRMwEQYK
15
+ CZImiZPyLGQBGRYDY29tMB4XDTE2MDQyNDAyNTEyM1oXDTE3MDQyNDAyNTEyM1ow
16
+ TjEaMBgGA1UEAwwRYWNjb3VudHNfcnVieWdlbXMxGzAZBgoJkiaJk/IsZAEZFgt0
17
+ aGVrb21wYW5lZTETMBEGCgmSJomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEB
18
+ BQADggEPADCCAQoCggEBANklzdaVeHtut6LTe/hrl6Krz2Z60InEbNb+TMG43tww
19
+ jBpWZrdU/SBkR3EYbTAQv/yGTuMHoVKGK2kDlFvdofW2hX0d14qPyYJUNYt+7VWE
20
+ 3UhPSxw1i6MxeU1QwfkIyaN8A5lj0225+rwI/mbplv+lSXPlJEroCQ9EfniZD4jL
21
+ URlrHWl/UejcQ32C1IzBwth3+nacrO1197v5nSdozFzQwm4groaggXn9F/WpThu+
22
+ MhcE4bfttwEjAfU3zAThyzOFoVPpACP+SwOuyPJSl02+9BiwzeAnFJDfge7+rsd5
23
+ 64W/VzBIklEKUZMmxZwr5DwpSXLrknBDtHLABG9Nr3cCAwEAAaOBljCBkzAJBgNV
24
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUP7v0f/qfa0LMrhkzHRI3l10X
25
+ LYIwLAYDVR0RBCUwI4EhYWNjb3VudHMrcnVieWdlbXNAdGhla29tcGFuZWUuY29t
26
+ MCwGA1UdEgQlMCOBIWFjY291bnRzK3J1YnlnZW1zQHRoZWtvbXBhbmVlLmNvbTAN
27
+ BgkqhkiG9w0BAQUFAAOCAQEASqdfJKMun1twosHfvdDH7Vgrb5VqX28qJ6MgnhjF
28
+ p+3HYTjYo/KMQqu78TegUFO5xQ4oumU0FTXADW0ryXZvUGV74M0zwqpFqeo8onII
29
+ lsVsWdMCLZS21M0uCQmcV+OQMNxL8jV3c0D3x9Srr9yO4oamW3seIdb+b9RfhmV2
30
+ ryr+NH8U/4xgzdJ4hWV4qk93nwigp4lwJ4u93XJ7Cdyw7itvaEPnn8HpCfzsiLcw
31
+ QwSfDGz6+zsImi5N3UT71+mk7YcviQSgvMRl3VkAv8MZ6wcJ5SQRpf9w0OeFH6Ln
32
+ nNbCoHiYeXX/lz/M6AIbxDIZZTwxcyvF7bdrQ2fbH5MsfQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2016-05-12 00:00:00.000000000 Z
12
35
  dependencies:
13
36
  - !ruby/object:Gem::Dependency
14
37
  name: rspec
@@ -42,22 +65,20 @@ description: ''
42
65
  email: accounts+git@thekompanee.com
43
66
  executables: []
44
67
  extensions: []
45
- extra_rdoc_files:
46
- - README.md
47
- - LICENSE
68
+ extra_rdoc_files: []
48
69
  files:
49
- - LICENSE
70
+ - LICENSE.txt
50
71
  - README.md
51
72
  - Rakefile
52
73
  - lib/referehencible.rb
53
74
  - lib/referehencible/version.rb
54
75
  - spec/lib/referehencible_spec.rb
55
76
  homepage: https://github.com/chirrpy/referehencible
56
- licenses: []
77
+ licenses:
78
+ - MIT
57
79
  metadata: {}
58
80
  post_install_message:
59
- rdoc_options:
60
- - "--charset = UTF-8"
81
+ rdoc_options: []
61
82
  require_paths:
62
83
  - lib
63
84
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -71,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
92
  - !ruby/object:Gem::Version
72
93
  version: '0'
73
94
  requirements: []
74
- rubyforge_project: referehencible
75
- rubygems_version: 2.4.5
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
76
97
  signing_key:
77
98
  specification_version: 4
78
99
  summary: Enable unique reference numbers on all the things
@@ -0,0 +1,3 @@
1
+ )L*�kn�
2
+ �D�Օ3(��@����ad�~
3
+ �Iٌ‹)�jԔ;$a�ۮ��̸��g�w�%(WL{�p���TH��pR�\�m���$7w�eI� T�[����γi��L���끑��0�i�y/0�a�R�Om�ٶ�x�;��>*:�b�E�j��n��#��Gy!)���"z�C�m�m�{��b/Gʬxd�����`tiٓZ! �R�������:���&3�Y9��UB/D0��E��pĬ^֒�^/�JBG�!J��<��M
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.