web_server_uid 1.0.0 → 1.0.1

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
- SHA512:
3
- metadata.gz: 1f4e8a55bfb690af19adc6020144a1239ce1958253d82cde98a5863735535889a451e116f12dcfd33927b3bbe8541930cc5260be1bf1c8f8021cccc09ad0b4f7
4
- data.tar.gz: a5b54a5ea1c6a90cca40e472fc7909b3ae23298f6d13cd4ddf54ed23940ad85c125c659d3465e30987aefce6e0e3446e01f6e020dcda4b9cf92ce1bb85c98697
5
2
  SHA1:
6
- metadata.gz: 29eb5fec9ff2853494d6752ae159f5df63a40977
7
- data.tar.gz: 7730d4f45312472340a561d486bdb960eb1a094e
3
+ metadata.gz: 1a8a676540be4df67822b2ca72623dde3800bb4c
4
+ data.tar.gz: cb182fae67d7d1cea39040248e800e4b2b744526
5
+ SHA512:
6
+ metadata.gz: 5385c0ce03a88ae0a4fd2f91b314e1a4fb1a86d736ef51cf0c5c1f2fae90f62e86d1e2142f423de470ea24664dd3ea30b5ecad9fb6a3e3f1eb231d5b68d0192e
7
+ data.tar.gz: 34ef20fb44cd5c59c8bbc75a0a2051ff50ea48a18414276df71d768a369af9fa85b230a53c62fecce13fb30531168c7ccbbeebf05b82e3452555c00fa9f437ad
@@ -110,7 +110,7 @@ class WebServerUid
110
110
  ]
111
111
 
112
112
  binary = components.pack("NNNN")
113
- from_binary(binary)
113
+ new(binary, :generated)
114
114
  end
115
115
 
116
116
  private
@@ -144,6 +144,7 @@ class WebServerUid
144
144
  #
145
145
  # ...and +type+ must be the corresponding format -- one of :binary, :hex, or :base64. (It is not possible to guess
146
146
  # the format 100% reliably from the inbound +raw_data+, since raw binary can happen to look like one of the others.)
147
+ # (+type+ can also be +:generated+, for exclusive use of +.generate+, above.)
147
148
  #
148
149
  # +options+ can contain:
149
150
  #
@@ -153,7 +154,7 @@ class WebServerUid
153
154
  # get exactly that character in the Base64 at the end, and this will translate to
154
155
  # extra data.
155
156
  def initialize(raw_data, type, options = { })
156
- raise ArgumentError, "Type must be one of :binary, :hex, or :base64, not #{type.inspect}" unless [ :binary, :hex, :base64 ].include?(type)
157
+ raise ArgumentError, "Type must be one of :binary, :hex, or :base64, not #{type.inspect}" unless [ :binary, :hex, :base64, :generated ].include?(type)
157
158
  @input_type = type
158
159
 
159
160
  @binary_components = case type
@@ -163,7 +164,7 @@ class WebServerUid
163
164
  when :base64 then
164
165
  @raw_binary_data = Base64.decode64(raw_data)
165
166
  @raw_binary_data.unpack("NNNN")
166
- when :binary then
167
+ when :binary, :generated then
167
168
  @raw_binary_data = raw_data
168
169
  @raw_binary_data.unpack("NNNN")
169
170
  else
@@ -193,6 +194,14 @@ class WebServerUid
193
194
  0
194
195
  end
195
196
 
197
+ def to_s
198
+ "<#{self.class.name} from #{@input_type}: #{to_hex_string}>"
199
+ end
200
+
201
+ def inspect
202
+ to_s
203
+ end
204
+
196
205
  include Comparable
197
206
 
198
207
  # ...well, except for this one. ;)
@@ -1,3 +1,3 @@
1
1
  class WebServerUid
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -74,6 +74,16 @@ describe WebServerUid do
74
74
  1000.times { ids << WebServerUid.generate }
75
75
  expect(ids.map(&:to_hex_string).uniq.length).to eq(1000)
76
76
  end
77
+
78
+ it "should turn itself into a string reasonably, and say where it's from" do
79
+ expect(@generated.to_s).to match(/generated/i)
80
+ expect(@generated.to_s).to match(/#{@generated.to_hex_string}/i)
81
+ end
82
+
83
+ it "should inspect itself reasonably, and say where it's from" do
84
+ expect(@generated.inspect).to match(/generated/i)
85
+ expect(@generated.inspect).to match(/#{@generated.to_hex_string}/i)
86
+ end
77
87
  end
78
88
 
79
89
  describe "known examples" do
@@ -154,6 +164,16 @@ describe WebServerUid do
154
164
  it "should have the right cookie version number" do
155
165
  expect(uid.cookie_version_number).to eq(2)
156
166
  end
167
+
168
+ it "should turn itself into a string reasonably, and say where it's from" do
169
+ expect(uid.to_s).to match(/#{uid.to_hex_string}/i)
170
+ expect(uid.to_s).to match(/#{type}/i)
171
+ end
172
+
173
+ it "should inspect itself reasonably, and say where it's from" do
174
+ expect(uid.inspect).to match(/#{uid.to_hex_string}/i)
175
+ expect(uid.inspect).to match(/#{type}/i)
176
+ end
157
177
  end
158
178
  end
159
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_server_uid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Geweke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-02-15 00:00:00 Z
12
+ date: 2014-02-18 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler