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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 912c9ad236b8c086fb7d334888350c35c863c2f9
4
- data.tar.gz: 99cb0828ab0d1334dfa735e11a38e0ee2b7e6037
3
+ metadata.gz: 2af97469abc84391a77a60f80c5da44789eda37e
4
+ data.tar.gz: 8949cba7c23211c9110bf9fa7229a6ab1d44dff4
5
5
  SHA512:
6
- metadata.gz: 7be443143e324aae5c099a6635b65082969bfcba7848ef77469ec008c27f52d3f3b87ee7ad7a0c609a05fb428a2d43d5d11099b413e871d3c701fec263efcf6e
7
- data.tar.gz: dcadda7b393f830271f0528a42a4aa3996699137034e7a5c524b61cccaf1d3a6830dbd2b933822330e5f9894b26eb12359ad759376f0f9c279ada8fb5b5af46c
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
@@ -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 using {Salesforce::Random}
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
@@ -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
- def safe
70
- SalesforceId(sensitive)
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
@@ -1,3 +1,3 @@
1
1
  module SalesforceId
2
- VERSION = "1.3.2"
2
+ VERSION = "1.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL