salesforce_id 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/salesforce_id.rb +6 -3
- data/lib/salesforce_id/random.rb +20 -2
- data/lib/salesforce_id/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2af97469abc84391a77a60f80c5da44789eda37e
|
4
|
+
data.tar.gz: 8949cba7c23211c9110bf9fa7229a6ab1d44dff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267d3107c694c631bbaaa5e1d87a1e648cc98366d23fc65c7a265043bbb82e0432426db11ad80d4b0dd2d59a5ea60c883cd755d3ef2a7aef19448e20b39b70cd
|
7
|
+
data.tar.gz: ce73d9946b2a52450415b68177a73d9ef99407513358dc82a39bb00ab7f9bbe644b93fd8285967dd8d40524d84c88e7a1813f3a6d2df6ff7f8d160e9d0dd0bff
|
data/README.md
CHANGED
@@ -117,8 +117,15 @@ SalesforceId::Random.invalid_insensitive_checksum # => 003G000001SUbc4I9D
|
|
117
117
|
# Generate a valid SalesforceId::Safe salesforce id
|
118
118
|
SalesforceId::Random.safe # => #<SalesforceId::Safe:0x007f86f2294c50 @value="003G000001SUbc4IAD">
|
119
119
|
|
120
|
+
# Generate a valid SalesforceId::Safe salesforce id with a prefix, useful for
|
121
|
+
# factory girl sequences
|
122
|
+
SalesforceId::Random.safe("foo") # => #<SalesforceId::Safe:0x007f86f2294c50 @value="fooG000001SUbc4IAD">
|
123
|
+
|
120
124
|
# Shorter version to perform `SalesforceId::Random.safe`
|
121
125
|
SalesforceId.random # => #<SalesforceId::Safe:0x007f86f2294c50 @value="003G000001SUbc4IAD">
|
126
|
+
|
127
|
+
# Shorter version to perform `SalesforceId::Random.safe` with prefix
|
128
|
+
SalesforceId.random("foo") # => #<SalesforceId::Safe:0x007f86f2294c50 @value="fooG000001SUbc4IAD">
|
122
129
|
```
|
123
130
|
|
124
131
|
#### RSpec matchers
|
data/lib/salesforce_id.rb
CHANGED
@@ -47,10 +47,13 @@ module SalesforceId
|
|
47
47
|
::SalesforceId::Safe.new(salesforce_id)
|
48
48
|
end
|
49
49
|
|
50
|
-
# Provides a randomly generated salesforce id
|
50
|
+
# Provides a randomly generated salesforce id.
|
51
|
+
# Alias of {Salesforce::Random#safe}
|
52
|
+
# @param prefix [String] prefix to be prepended to the id, see
|
53
|
+
# {Salesforce::Random#safe} for additional details
|
51
54
|
# @return [SalesforceId::Safe]
|
52
|
-
def random
|
53
|
-
::SalesforceId::Random.safe
|
55
|
+
def random(prefix = '')
|
56
|
+
::SalesforceId::Random.safe(prefix)
|
54
57
|
end
|
55
58
|
|
56
59
|
end
|
data/lib/salesforce_id/random.rb
CHANGED
@@ -65,9 +65,27 @@ module ::SalesforceId
|
|
65
65
|
end
|
66
66
|
|
67
67
|
# Creates a random salesforce id enclosed in {SalesforceId::Safe} object
|
68
|
+
# @param prefix [String] an optional prefix to be prepended to the ID,
|
69
|
+
# useful for FactoryGirl sequences, must use salesforce id valid
|
70
|
+
# characters for case-sensitive IDs
|
68
71
|
# @return [SalesforceId::Safe]
|
69
|
-
|
70
|
-
|
72
|
+
# @raise [ArgumentError] if prefix is longer than or contains invalid
|
73
|
+
# characters for case-sensitive id
|
74
|
+
def safe(prefix = "")
|
75
|
+
prefix = prefix.to_s
|
76
|
+
|
77
|
+
raise_prefix_too_long! if prefix.size > ::SalesforceId::SENSITIVE_SIZE
|
78
|
+
|
79
|
+
id = sensitive
|
80
|
+
id = prefix + sensitive[(prefix.size..id.size)]
|
81
|
+
|
82
|
+
SalesforceId(id)
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def raise_prefix_too_long!
|
88
|
+
raise ArgumentError, "Prefix must be shorter than insensitive length"
|
71
89
|
end
|
72
90
|
|
73
91
|
end
|