salesforce_id 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: 4898a0b33f8f54372cff05bd0b65c0705c544a8c
4
- data.tar.gz: c9f1d80e51b4229bc9bd636fb5a684c050494cf6
3
+ metadata.gz: bc150f154ee214c5bd79aabbffc61d075dce6b14
4
+ data.tar.gz: f381ee50f307f0002b6e115986c518a929b7238e
5
5
  SHA512:
6
- metadata.gz: 4b6885c6be43f1ead7dc991a006278faaad1968b734324eed060b13f9801f7ca8868ca8602735fb1a7c5992b9772a50426d0d8ab96e7c32aae11ff49086b4f88
7
- data.tar.gz: fe2d8cab75769f2eba6f618a9ab9072e09e3c8938a6d4f633ef5a338afa8926cff19e0e6ff25d7ed6748bb60b6434d06926f73a740bab010ab8e5b7325ddd444
6
+ metadata.gz: 9f8af02768f5bb532fa7b23d8f7dbe0dc97747cea93b88e507503422c03f41e168732e7fb2a62d4a5fc552c78a71bc65ea571dd04e52db000509ed038c687b80
7
+ data.tar.gz: 1deb2b58d231d7efe7cbf5915cb5a1da3fae4371dd57eb87e66ac1cb1f63d09ddc51ad7e007813df9f1d23e566f6f3a059d92bad211ee6ba7fc5a53674ba39b0
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # SalesforceId [![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](https://travis-ci.org/Fire-Dragon-DoL/salesforce_id.svg?branch=master) [![Code Climate](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/badges/gpa.svg)](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id) [![Test Coverage](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/badges/coverage.svg)](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/coverage)
1
+ # SalesforceId [![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](https://travis-ci.org/Fire-Dragon-DoL/salesforce_id.svg?branch=master) [![Code Climate](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/badges/gpa.svg)](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id) [![Test Coverage](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/badges/coverage.svg)](https://codeclimate.com/github/Fire-Dragon-DoL/salesforce_id/coverage) [![Gem Version](https://badge.fury.io/rb/salesforce_id.svg)](https://badge.fury.io/rb/salesforce_id)
2
+
3
+ [![Join the chat at https://gitter.im/Fire-Dragon-DoL/salesforce_id](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Fire-Dragon-DoL/salesforce_id?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
4
 
3
5
  Gem to properly convert from and to 15 characters case sensitive format and
4
6
  18 characters case insensitive format for salesforce record ID.
@@ -55,6 +57,36 @@ SalesforceId.insensitive?(id15) # => false
55
57
  SalesforceId.insensitive?(nil) # => false
56
58
  ```
57
59
 
60
+ There is also a simple class that is a [value object](http://www.sitepoint.com/value-objects-explained-with-ruby/) which can be used in the following way:
61
+
62
+ ```ruby
63
+ id = SalesforceId::Safe.new("003G000001SUbc4")
64
+ # Or shorter version
65
+ id = SalesforceId.id("003G000001SUbc4")
66
+ # It doesn't instanciate a new object if a `SalesforceId::Safe` is passed
67
+ id2 = SalesforceId.id(id)
68
+ id.equal?(id2) # => true
69
+
70
+ # It provides a few nice methods
71
+ id3 = SalesforceId.id("004A000002SUbc4IAD")
72
+
73
+ # It always handles everything in case-insensitive repaired casing format
74
+ id.to_s == "003G000001SUbc4IAD" # => true
75
+
76
+ # It can be compared with other ids
77
+ id == id3 # => false
78
+ id == id # => true
79
+
80
+ # It can be converted to JSON
81
+ id.to_json # => "003G000001SUbc4IAD"
82
+
83
+ # It can be converted to case-sensitive format
84
+ id.to_sensitive # => "003G000001SUbc4"
85
+
86
+ # It can be converted to case-insensitive format
87
+ id.to_insensitive # => "003G000001SUbc4IAD"
88
+ ```
89
+
58
90
  ## Documentation
59
91
 
60
92
  Methods are documented in [salesforce_id_ext.h](https://github.com/Fire-Dragon-DoL/salesforce_id/blob/master/ext/salesforce_id/salesforce_id_ext.h), this file is
@@ -1,6 +1,14 @@
1
1
  require 'salesforce_id/version'
2
2
  require 'salesforce_id/salesforce_id'
3
+ require 'salesforce_id/safe'
3
4
 
4
5
  module SalesforceId
5
6
  extend self
7
+
8
+ def id(salesforce_id)
9
+ return salesforce_id if salesforce_id.kind_of?(::SalesforceId::Safe)
10
+
11
+ ::SalesforceId::Safe.new(salesforce_id)
12
+ end
13
+
6
14
  end
@@ -0,0 +1,67 @@
1
+ require 'salesforce_id'
2
+ require 'salesforce_id/safe'
3
+
4
+ module SalesforceId
5
+
6
+ # Rapresents a salesforce id as an object allowing for comparison and usage
7
+ # in a safe fashion thanks to using fixed format. Internally will store and
8
+ # keep any salesforce id using the case-insensitive format but with repaired
9
+ # casing, which should offer maximum safety
10
+ class Safe
11
+ include Comparable
12
+
13
+ # @param id [String] valid salesforce id
14
+ def initialize(id)
15
+ id = id.to_s
16
+
17
+ unless ::SalesforceId.valid?(id)
18
+ raise ArgumentError, "Salesforce ID not valid"
19
+ end
20
+
21
+ @value = SalesforceId.to_insensitive(id.dup).freeze
22
+ end
23
+
24
+ # @return [String] text composing salesforce id, string is **frozen**
25
+ def to_s
26
+ value
27
+ end
28
+
29
+ def as_json(*args)
30
+ to_s
31
+ end
32
+
33
+ # In JSON format, it's a plain string
34
+ def to_json(*args)
35
+ as_json
36
+ end
37
+
38
+ # Comparison with string is avoided because otherwise either it needed to
39
+ # allocate a salesforce id or it would fail if not in case insensitive
40
+ # format
41
+ # @param other [SalesforceId::Safe]
42
+ def <=>(other)
43
+ return nil unless other.kind_of?(self.class)
44
+
45
+ to_s <=> other.to_s
46
+ end
47
+
48
+ # @return [String] salesforce id in case-sensitive format, string is **not**
49
+ # frozen
50
+ def to_sensitive
51
+ SalesforceId.to_sensitive(value)
52
+ end
53
+
54
+ # @return [String] salesforce id in case-insensitive format, string is
55
+ # **not** frozen
56
+ def to_insensitive
57
+ to_s.dup
58
+ end
59
+
60
+ protected
61
+
62
+ # Internal value of salesforce safe id
63
+ attr_reader :value
64
+
65
+ end
66
+
67
+ end
@@ -1,3 +1,3 @@
1
1
  module SalesforceId
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fire-Dragon-DoL
@@ -150,6 +150,7 @@ files:
150
150
  - ext/salesforce_id/validate_id.c
151
151
  - ext/salesforce_id/validate_id.h
152
152
  - lib/salesforce_id.rb
153
+ - lib/salesforce_id/safe.rb
153
154
  - lib/salesforce_id/version.rb
154
155
  - salesforce_id.gemspec
155
156
  homepage: https://github.com/Fire-Dragon-DoL/salesforce_id