id_shuffler 0.0.0 → 0.0.1

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.
@@ -93,18 +93,18 @@ static VALUE r_base32_unshuffle(VALUE self, VALUE shuffled_str, VALUE key_str) {
93
93
  lfsr_num = lfsr_num & 32767;
94
94
  l = (r ^ lfsr_num);
95
95
  r = l_orig;
96
- }
96
+ }
97
97
  // return the resulting original number as a ruby fixnum
98
98
  unsigned long original;
99
- original = (l << 15) + r;
99
+ original = (l << 15) + r;
100
100
  return ULONG2NUM(original);
101
101
  }
102
102
 
103
103
  void Init_id_shuffler(void) {
104
104
  // add two class methods to our IdShuffler class: shuffle and unshuffle, each
105
105
  // of which take the object to be [unshuffled] and the key.
106
- VALUE klass = rb_define_class("IdShuffler", rb_cObject);
107
- rb_define_singleton_method(klass, "shuffle", r_base32_shuffle, 2);
108
- rb_define_singleton_method(klass, "unshuffle", r_base32_unshuffle, 2);
106
+ VALUE klass = rb_define_class("IdShuffler", rb_cObject);
107
+ rb_define_singleton_method(klass, "shuffle_with_raw_key", r_base32_shuffle, 2);
108
+ rb_define_singleton_method(klass, "unshuffle_with_raw_key", r_base32_unshuffle, 2);
109
109
  }
110
110
 
data/lib/id_shuffler.rb CHANGED
@@ -18,11 +18,23 @@ class IdShuffler
18
18
  end
19
19
 
20
20
  def shuffle(i)
21
- self.class.shuffle(i.to_i, @key)
21
+ self.class.shuffle_with_raw_key(i.to_i, @key)
22
22
  end
23
23
 
24
24
  def unshuffle(s)
25
- self.class.unshuffle(s.to_s, @key)
25
+ self.class.unshuffle_with_raw_key(s.to_s, @key)
26
+ end
27
+
28
+ def self.shuffle(i, key)
29
+ @keycache ||= {}
30
+ @keycache[key] ||= Digest::MD5.digest(key)
31
+ shuffle_with_raw_key(i.to_i, @keycache[key])
32
+ end
33
+
34
+ def self.unshuffle(s, key)
35
+ @keycache ||= {}
36
+ @keycache[key] ||= Digest::MD5.digest(key)
37
+ unshuffle_with_raw_key(s.to_s, @keycache[key])
26
38
  end
27
39
 
28
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id_shuffler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: