id_pack 0.1.0 → 1.0.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: e8731fab4947eaab425af39652bdb53123f64b66
4
- data.tar.gz: 7f571ff94f358063908bf0c8f0d763431c2c5a87
3
+ metadata.gz: 40f1290972ca537009fdccbb9f92d43b945fc7f0
4
+ data.tar.gz: aca88be54e625a021247f0d0e7cd890c3a4248cd
5
5
  SHA512:
6
- metadata.gz: a9de58d8ce76c8f4aedcee05a7e0b2b7dac0838da532c8b7f90b23c347d16b3c9bc442a20110b7ec6635a7e117a0ae253c0339b045ace3a17188b2c201f2dac7
7
- data.tar.gz: 7f81c9eef199e29ec689e0a632ade5b8fe536a2cfd11f9dfd02ca942b7ab10c562df01bd46249e8556467dc15d5bf313dc129d72e61a8827015eb12d7e172719
6
+ metadata.gz: 13a3bb10dd108bf19697cf285dbe16a91fb8dcf494c99bd4b667c1a81ea318b5d6088263b8c705694c7b637a6369f4ffa1f2967b6e41c56e133606f8b9ef8b51
7
+ data.tar.gz: 40644148114649ee617701d72a487eb18311ef2fc54bbeec9783f477e0220a02508534ffae7988a63c27fbe276a0d5ffaabaedd5e1453059b4d2d389e5452082
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in uuid_pack.gemspec
3
+ # Specify your gem's dependencies in id_pack.gemspec
4
4
  gemspec
5
+
6
+ gem 'codecov', :require => false, :group => :test
data/Gemfile.lock CHANGED
@@ -1,12 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- id_pack (0.1.0)
4
+ id_pack (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ codecov (0.1.10)
10
+ json
11
+ simplecov
12
+ url
9
13
  diff-lcs (1.3)
14
+ docile (1.1.5)
15
+ json (2.1.0)
10
16
  rake (10.5.0)
11
17
  rspec (3.6.0)
12
18
  rspec-core (~> 3.6.0)
@@ -21,12 +27,19 @@ GEM
21
27
  diff-lcs (>= 1.2.0, < 2.0)
22
28
  rspec-support (~> 3.6.0)
23
29
  rspec-support (3.6.0)
30
+ simplecov (0.15.1)
31
+ docile (~> 1.1.0)
32
+ json (>= 1.8, < 3)
33
+ simplecov-html (~> 0.10.0)
34
+ simplecov-html (0.10.2)
35
+ url (0.3.2)
24
36
 
25
37
  PLATFORMS
26
38
  ruby
27
39
 
28
40
  DEPENDENCIES
29
41
  bundler (~> 1.15)
42
+ codecov
30
43
  id_pack!
31
44
  rake (~> 10.0)
32
45
  rspec (~> 3.6)
data/README.adoc ADDED
@@ -0,0 +1,212 @@
1
+ = id_pack
2
+
3
+ image:https://img.shields.io/gem/v/id_pack.svg[
4
+ Gem Version, link="https://rubygems.org/gems/id_pack"]
5
+ image:https://img.shields.io/travis/riboseinc/id_pack/master.svg[
6
+ Build Status, link="https://travis-ci.org/riboseinc/id_pack"]
7
+ image:https://api.codeclimate.com/v1/badges/655d7aa547daa7b45148/maintainability[
8
+ "Code Climate - Maintainability", link="https://codeclimate.com/github/riboseinc/id_pack/maintainability"]
9
+ image:https://img.shields.io/codecov/c/github/riboseinc/id_pack.svg[
10
+ "Test Coverage", link="https://codecov.io/gh/riboseinc/id_pack"]
11
+
12
+ == Introduction
13
+
14
+ This gem provides functionality to compress and decompress two different types
15
+ of objects:
16
+
17
+ 1. a contiguous range or multiple contiguous ranges of integer ID
18
+ 2. a set of UUID
19
+
20
+ as a single string.
21
+
22
+ Both Ruby and Javascript implementations are provided.
23
+
24
+ Javascript support for Rails is provided by means of a Rails engine (`IdPack::Engine`).
25
+
26
+ Further, for integer ID ranges, it provides serialization of a concept called
27
+ `sync_str`, which stands for "synchronization string".
28
+
29
+ `sync_str` represents a mapping from ID to timestamp.
30
+ It is typically generated on the client side for the server side.
31
+ Armed with the `sync_str`, the server knows which objects the client requires,
32
+ by comparing the timestamps from the `sync_str` with the update times of the
33
+ corresponding objects from the database, so synchronization could be done with
34
+ minimal waste of bandwidth.
35
+
36
+ Timestamps are really just integers, _e.g._ `Time.now.to_i`.
37
+
38
+
39
+ == Installation
40
+
41
+ There are at least two ways to install this:
42
+
43
+ A. The quickest way is to `gem install` on the terminal:
44
+ +
45
+ [source,bash]
46
+ ....
47
+ gem install id_pack
48
+ ....
49
+
50
+ B. If your application has a `Gemfile`, add the following line:
51
+ +
52
+ [source,ruby]
53
+ ....
54
+ gem 'id_pack'
55
+ ....
56
+ +
57
+ And then execute:
58
+ +
59
+ [source,bash]
60
+ ....
61
+ bundle
62
+ ....
63
+
64
+ == Usage
65
+
66
+ To experiment with the code, run `bin/console` for an interactive prompt.
67
+
68
+ [source,ruby]
69
+ ----
70
+ require 'id_pack'
71
+ ----
72
+
73
+ === IdPacker
74
+
75
+ [source,ruby]
76
+ ----
77
+ id_packer = IdPack::IdPacker.new
78
+ ----
79
+
80
+ To encode/decode a set of IDs:
81
+
82
+ [source,ruby]
83
+ ----
84
+ ids = [5, 6, 21, 23, 25]
85
+ encoded_ids = id_packer.encode(ids) #=> "_F~C_P.V"
86
+ decoded_ids = id_packer.decode(encoded_ids) #=> [5, 6, 21, 23, 25]
87
+ ids == decoded_ids #=> true
88
+ ----
89
+
90
+ To work with `sync_str`:
91
+
92
+ [source,ruby]
93
+ ----
94
+ ids_synced_at = {
95
+ 1 => 1510294889,
96
+ 2 => 1510292639,
97
+ 10 => 1510279639,
98
+ }
99
+
100
+ sync_str = id_packer.encode_sync_str(ids_synced_at)
101
+ #=> "IwVmAYCYHYE4DYDMsg,IxA,IwVgTCAMQ,ExA,IwZgDBQ,IwBiA,AxA"
102
+
103
+ decoded_sync_map = id_packer.decode_sync_str(sync_str)
104
+ #=> {1=>1510294889, 2=>1510292639, 10=>1510279639}
105
+
106
+ ids_synced_at == decoded_sync_map
107
+ #=> true
108
+ ----
109
+
110
+ ==== Advanced `sync_str` usage
111
+
112
+ `IdPacker#decode_sync_str` optionally supports a `base_timestamp`:
113
+
114
+ [source,ruby]
115
+ ----
116
+ base_timestamp2 = 1000
117
+ decoded_sync_map2 = id_packer.decode_sync_str(sync_str, base_timestamp2)
118
+ #=> {1=>1510295889, 2=>1510293639, 10=>1510280639}
119
+
120
+ base_timestamp3 = - ids_synced_at.min[1]
121
+ decoded_sync_map3 = id_packer.decode_sync_str(sync_str, base_timestamp3)
122
+ #=> {1=>0, 2=>-2250, 10=>-15250}
123
+
124
+ base_timestamp4 = - ids_synced_at.max[1]
125
+ decoded_sync_map4 = id_packer.decode_sync_str(sync_str, base_timestamp4)
126
+ #=> {1=>15250, 2=>13000, 10=>0}
127
+ ----
128
+
129
+ `base_timestamp` is typically specified to reverse any normalization of
130
+ timestamps done on the client side (not shown in this README).
131
+
132
+ === UuidPacker
133
+
134
+ [source,ruby]
135
+ ----
136
+ uuid_packer = IdPack::UuidPacker.new
137
+ ----
138
+
139
+ [source,ruby]
140
+ ----
141
+ uuids = [
142
+ 'ea8bed36-a73d-4fff-af36-32162274dfd1',
143
+ '22347af1-7c60-48e0-8cc5-a30746812267',
144
+ '3e514775-bfdb-44f9-92b2-c4c53a7dc89d',
145
+ ]
146
+ ----
147
+
148
+ To encode/decode a set of UUIDs, first, specify the set of encoding characters:
149
+
150
+ [source,ruby]
151
+ ----
152
+ base_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-_'
153
+ ----
154
+
155
+ Also, decide whether we want to preserve the order of the UUIDs:
156
+
157
+ [source,ruby]
158
+ ----
159
+ ordered = true
160
+ ----
161
+
162
+ [source,ruby]
163
+ ----
164
+ encoded_uuids = uuid_packer.alphanum_compress(uuids, base_string, ordered)
165
+ #=> "Rf2XIjQmNnr_8rzlbLfRV+ZEgWLgxaMxBxIGPo9eLES5E75coyNNSZ8i2_tdxRT4"
166
+
167
+ decoded_uuids = uuid_packer.alphanum_decompress(encoded_uuids, base_string)
168
+ #=> ["ea8bed36-a73d-4fff-af36-32162274dfd1", "22347af1-7c60-48e0-8cc5-a30746812267", "3e514775-bfdb-44f9-92b2-c4c53a7dc89d"]
169
+
170
+ uuids == decoded_uuids
171
+ #=> true
172
+ ----
173
+
174
+
175
+ If we don't care for the order:
176
+
177
+ [source,ruby]
178
+ ----
179
+ ordered = false
180
+ ----
181
+
182
+ [source,ruby]
183
+ ----
184
+ unordered_encoded_uuids = uuid_packer.alphanum_compress(uuids, base_string, ordered)
185
+ unordered_decoded_uuids = uuid_packer.alphanum_decompress(unordered_encoded_uuids, base_string)
186
+
187
+ uuids == unordered_decoded_uuids
188
+ #=> false
189
+
190
+ uuids.sort == unordered_decoded_uuids.sort
191
+ #=> true
192
+ ----
193
+
194
+ == Development
195
+
196
+ After checking out the repo, run `bin/setup` to install dependencies.
197
+ Then, run `bundle exec rake spec` to run the tests.
198
+ You can also run `bin/console` for an interactive prompt that will allow you to
199
+ experiment.
200
+
201
+ == Contributing
202
+
203
+ Bug reports and pull requests are welcome on GitHub at
204
+ https://github.com/riboseinc/id_pack. This project is intended to be a
205
+ safe, welcoming space for collaboration, and contributors are expected
206
+ to adhere to the http://contributor-covenant.org[Contributor Covenant]
207
+ code of conduct.
208
+
209
+ == License
210
+
211
+ The gem is available as open source under the terms of the
212
+ http://opensource.org/licenses/MIT[MIT License].
@@ -18,12 +18,12 @@
18
18
  *
19
19
  * Examples:
20
20
  *
21
- * // encrypt the items in an Array
21
+ * // encode the items in an Array
22
22
  * var collection = [5, 6, 21, 23, 25];
23
23
  * IdPacker.encodeHashKeys(collection);
24
24
  * => "_E~C_O.V"
25
25
  *
26
- * // encrypt the keys of an Object
26
+ * // encode the keys of an Object
27
27
  * var collection = {
28
28
  * 5: "a",
29
29
  * 6: "b",
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "uuid_pack"
4
+ require "id_pack"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -11,15 +11,15 @@ module IdPack
11
11
  #
12
12
  # Example:
13
13
  #
14
- # IdPack::IdPacker.encode([5, 6, 21, 23, 25]) # => "_F~C_P.V"
14
+ # IdPack::IdPacker.new.encode([5, 6, 21, 23, 25]) # => "_F~C_P.V"
15
15
  #
16
16
  # decode:
17
17
  # mainly used by the server to convert the compressed string back into
18
18
  # the integer array
19
19
  #
20
- # Example:
20
+ # Example:
21
21
  #
22
- # IdPack::IdPacker.decode("_F~C_P.V") # => [5, 6, 21, 23, 25]
22
+ # IdPack::IdPacker.new.decode("_F~C_P.V") # => [5, 6, 21, 23, 25]
23
23
 
24
24
  class IdPacker
25
25
 
@@ -1,3 +1,3 @@
1
1
  module IdPack
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id_pack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -66,7 +66,7 @@ files:
66
66
  - Gemfile
67
67
  - Gemfile.lock
68
68
  - LICENSE
69
- - README.md
69
+ - README.adoc
70
70
  - Rakefile
71
71
  - app/assets/javascripts/lib/id-packer.js
72
72
  - app/assets/javascripts/lib/lz-string.js
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  version: '0'
102
102
  requirements: []
103
103
  rubyforge_project:
104
- rubygems_version: 2.5.2
104
+ rubygems_version: 2.6.8
105
105
  signing_key:
106
106
  specification_version: 4
107
107
  summary: Compression and packing methods for singular and collection IDs and UUIDs.
data/README.md DELETED
@@ -1,39 +0,0 @@
1
- # IdPack
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/id_pack`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'id_pack'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install id_pack
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at
36
- https://github.com/riboseinc/id_pack. This project is intended to be a safe,
37
- welcoming space for collaboration, and contributors are expected to adhere to
38
- the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
-