hoodie 0.5.5 → 1.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +19 -0
- data/Rakefile +8 -23
- data/hoodie.gemspec +0 -23
- data/lib/hoodie.rb +40 -48
- data/lib/hoodie/configuration.rb +39 -2
- data/lib/hoodie/core_ext/blank.rb +6 -6
- data/lib/hoodie/core_ext/hash.rb +108 -13
- data/lib/hoodie/core_ext/string.rb +5 -3
- data/lib/hoodie/core_ext/try.rb +4 -3
- data/lib/hoodie/inflections.rb +18 -0
- data/lib/hoodie/inflections/defaults.rb +17 -0
- data/lib/hoodie/inflections/inflections.rb +17 -0
- data/lib/hoodie/inflections/rules_collection.rb +17 -0
- data/lib/hoodie/logging.rb +22 -4
- data/lib/hoodie/stash.rb +83 -80
- data/lib/hoodie/stash/disk_store.rb +142 -118
- data/lib/hoodie/stash/mem_store.rb +10 -9
- data/lib/hoodie/stash/memoizable.rb +46 -0
- data/lib/hoodie/utils.rb +13 -183
- data/lib/hoodie/utils/ansi.rb +199 -0
- data/lib/hoodie/utils/crypto.rb +288 -0
- data/lib/hoodie/utils/equalizer.rb +146 -0
- data/lib/hoodie/utils/file_helper.rb +225 -0
- data/lib/hoodie/utils/konstruktor.rb +77 -0
- data/lib/hoodie/utils/machine.rb +83 -0
- data/lib/hoodie/utils/os.rb +56 -0
- data/lib/hoodie/utils/retry.rb +235 -0
- data/lib/hoodie/utils/timeout.rb +54 -0
- data/lib/hoodie/utils/url_helper.rb +104 -0
- data/lib/hoodie/version.rb +4 -4
- metadata +13 -234
- data/lib/hoodie/identity_map.rb +0 -96
- data/lib/hoodie/memoizable.rb +0 -43
- data/lib/hoodie/obfuscate.rb +0 -121
- data/lib/hoodie/observable.rb +0 -309
- data/lib/hoodie/os.rb +0 -43
- data/lib/hoodie/proxy.rb +0 -68
- data/lib/hoodie/rash.rb +0 -125
- data/lib/hoodie/timers.rb +0 -355
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'thread'
|
21
|
+
|
22
|
+
module Hoodie
|
23
|
+
# Class methods that are added when you include Hoodie::Timeout
|
24
|
+
#
|
25
|
+
module Timeout
|
26
|
+
# Methods are also available as module-level methods as well as a mixin.
|
27
|
+
extend self
|
28
|
+
|
29
|
+
# Wait the given number of seconds for the block operation to complete.
|
30
|
+
# Intended to be a simpler and more reliable replacement to the Ruby
|
31
|
+
# standard library `Timeout::timeout` method.
|
32
|
+
#
|
33
|
+
# @param [Integer] seconds
|
34
|
+
# Number of seconds to wait for the block to terminate. Any number may
|
35
|
+
# be used, including Floats to specify fractional seconds. A value of 0
|
36
|
+
# or nil will execute the block without any timeout.
|
37
|
+
#
|
38
|
+
# @return [Object]
|
39
|
+
# Result of the block if the block completed before the timeout,
|
40
|
+
# otherwise raises a TimeoutError exception.
|
41
|
+
#
|
42
|
+
# @raise [Hoodie::TimeoutError]
|
43
|
+
# When the block operation does not complete in the alloted time.
|
44
|
+
#
|
45
|
+
# @see Ruby Timeout::timeout
|
46
|
+
#
|
47
|
+
def timeout(seconds)
|
48
|
+
thread = Thread.new { Thread.current[:result] = yield }
|
49
|
+
thread.join(seconds) ? (return thread[:result]) : (raise TimeoutError)
|
50
|
+
ensure
|
51
|
+
Thread.kill(thread) unless thread.nil?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module Hoodie
|
21
|
+
# Class methods that are added when you include Hoodie
|
22
|
+
#
|
23
|
+
module UrlHelper
|
24
|
+
# Methods are also available as module-level methods as well as a mixin.
|
25
|
+
extend self
|
26
|
+
|
27
|
+
# Return a cleanly join URI/URL segments into a cleanly normalized URL
|
28
|
+
# that the libraries can use when constructing URIs. URI.join is pure
|
29
|
+
# evil.
|
30
|
+
#
|
31
|
+
# @param [Array<String>] paths
|
32
|
+
# the list of parts to join
|
33
|
+
#
|
34
|
+
# @return [URI]
|
35
|
+
#
|
36
|
+
def uri_join(*paths)
|
37
|
+
return nil if paths.length == 0
|
38
|
+
leadingslash = paths[0][0] == '/' ? '/' : ''
|
39
|
+
trailingslash = paths[-1][-1] == '/' ? '/' : ''
|
40
|
+
paths.map! { |path| path.sub(/^\/+/, '').sub(/\/+$/, '') }
|
41
|
+
leadingslash + paths.join('/') + trailingslash
|
42
|
+
end
|
43
|
+
|
44
|
+
# Unshorten a shortened URL.
|
45
|
+
#
|
46
|
+
# @param url [String] A shortened URL
|
47
|
+
#
|
48
|
+
# @param [Hash] opts
|
49
|
+
#
|
50
|
+
# @option opts [Integer] :max_level
|
51
|
+
# max redirect times
|
52
|
+
#
|
53
|
+
# @option opts [Integer] :timeout
|
54
|
+
# timeout in seconds, for every request
|
55
|
+
#
|
56
|
+
# @option opts [Boolean] :use_cache
|
57
|
+
# use cached result if available
|
58
|
+
#
|
59
|
+
# @return Original url, a url that does not redirects
|
60
|
+
#
|
61
|
+
def unshorten(url, opts= {})
|
62
|
+
options = {
|
63
|
+
max_level: opts.fetch(:max_level, 10),
|
64
|
+
timeout: opts.fetch(:timeout, 2),
|
65
|
+
use_cache: opts.fetch(:use_cache, true)
|
66
|
+
}
|
67
|
+
url = (url =~ /^https?:/i) ? url : "http://#{url}"
|
68
|
+
__unshorten__(url, options)
|
69
|
+
end
|
70
|
+
|
71
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
72
|
+
|
73
|
+
@@cache = { }
|
74
|
+
|
75
|
+
# @api private
|
76
|
+
def __unshorten__(url, options, level = 0)
|
77
|
+
return @@cache[url] if options[:use_cache] && @@cache[url]
|
78
|
+
return url if level >= options[:max_level]
|
79
|
+
uri = URI.parse(url) rescue nil
|
80
|
+
return url if uri.nil?
|
81
|
+
|
82
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
83
|
+
http.open_timeout = options[:timeout]
|
84
|
+
http.read_timeout = options[:timeout]
|
85
|
+
http.use_ssl = true if uri.scheme == 'https'
|
86
|
+
|
87
|
+
if uri.path && uri.query
|
88
|
+
response = http.request_head("#{uri.path}?#{uri.query}") rescue nil
|
89
|
+
elsif uri.path && !uri.query
|
90
|
+
response = http.request_head(uri.path) rescue nil
|
91
|
+
else
|
92
|
+
response = http.request_head('/') rescue nil
|
93
|
+
end
|
94
|
+
|
95
|
+
if response.is_a? Net::HTTPRedirection and response['location'] then
|
96
|
+
location = URI.encode(response['location'])
|
97
|
+
location = (uri + location).to_s if location
|
98
|
+
@@cache[url] = __unshorten__(location, options, level + 1)
|
99
|
+
else
|
100
|
+
url
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/hoodie/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
#
|
3
|
-
# Author:
|
4
|
-
#
|
5
|
-
# Copyright (C) 2014-2015 Stefano Harding
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
4
|
+
# License: Apache License, Version 2.0
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
@@ -18,5 +18,5 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
module Hoodie
|
21
|
-
VERSION = '0.
|
21
|
+
VERSION = '1.0.1'
|
22
22
|
end
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Harding
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: anemone
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.7.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.7.2
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: hitimes
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: rake
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,48 +52,6 @@ dependencies:
|
|
80
52
|
- - ">="
|
81
53
|
- !ruby/object:Gem::Version
|
82
54
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '3.2'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '3.2'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: fuubar
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '2.0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '2.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.9'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.9'
|
125
55
|
- !ruby/object:Gem::Dependency
|
126
56
|
name: inch
|
127
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,160 +80,6 @@ dependencies:
|
|
150
80
|
- - ">="
|
151
81
|
- !ruby/object:Gem::Version
|
152
82
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: guard
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: guard-shell
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - ">="
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - ">="
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
|
-
- !ruby/object:Gem::Dependency
|
182
|
-
name: guard-yard
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: guard-rubocop
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - ">="
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: '0'
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - ">="
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: '0'
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: guard-rspec
|
211
|
-
requirement: !ruby/object:Gem::Requirement
|
212
|
-
requirements:
|
213
|
-
- - ">="
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '0'
|
216
|
-
type: :development
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
requirements:
|
220
|
-
- - ">="
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '0'
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: ruby_gntp
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: rubocop
|
239
|
-
requirement: !ruby/object:Gem::Requirement
|
240
|
-
requirements:
|
241
|
-
- - ">="
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: '0'
|
244
|
-
type: :development
|
245
|
-
prerelease: false
|
246
|
-
version_requirements: !ruby/object:Gem::Requirement
|
247
|
-
requirements:
|
248
|
-
- - ">="
|
249
|
-
- !ruby/object:Gem::Version
|
250
|
-
version: '0'
|
251
|
-
- !ruby/object:Gem::Dependency
|
252
|
-
name: geminabox-rake
|
253
|
-
requirement: !ruby/object:Gem::Requirement
|
254
|
-
requirements:
|
255
|
-
- - ">="
|
256
|
-
- !ruby/object:Gem::Version
|
257
|
-
version: '0'
|
258
|
-
type: :development
|
259
|
-
prerelease: false
|
260
|
-
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
requirements:
|
262
|
-
- - ">="
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
version: '0'
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: version
|
267
|
-
requirement: !ruby/object:Gem::Requirement
|
268
|
-
requirements:
|
269
|
-
- - ">="
|
270
|
-
- !ruby/object:Gem::Version
|
271
|
-
version: '0'
|
272
|
-
type: :development
|
273
|
-
prerelease: false
|
274
|
-
version_requirements: !ruby/object:Gem::Requirement
|
275
|
-
requirements:
|
276
|
-
- - ">="
|
277
|
-
- !ruby/object:Gem::Version
|
278
|
-
version: '0'
|
279
|
-
- !ruby/object:Gem::Dependency
|
280
|
-
name: thor-scmversion
|
281
|
-
requirement: !ruby/object:Gem::Requirement
|
282
|
-
requirements:
|
283
|
-
- - ">="
|
284
|
-
- !ruby/object:Gem::Version
|
285
|
-
version: '0'
|
286
|
-
type: :development
|
287
|
-
prerelease: false
|
288
|
-
version_requirements: !ruby/object:Gem::Requirement
|
289
|
-
requirements:
|
290
|
-
- - ">="
|
291
|
-
- !ruby/object:Gem::Version
|
292
|
-
version: '0'
|
293
|
-
- !ruby/object:Gem::Dependency
|
294
|
-
name: semverse
|
295
|
-
requirement: !ruby/object:Gem::Requirement
|
296
|
-
requirements:
|
297
|
-
- - ">="
|
298
|
-
- !ruby/object:Gem::Version
|
299
|
-
version: '0'
|
300
|
-
type: :development
|
301
|
-
prerelease: false
|
302
|
-
version_requirements: !ruby/object:Gem::Requirement
|
303
|
-
requirements:
|
304
|
-
- - ">="
|
305
|
-
- !ruby/object:Gem::Version
|
306
|
-
version: '0'
|
307
83
|
description: A collection of hipster methods and hoodie tools to make even the nerdy
|
308
84
|
rubyist look cool.
|
309
85
|
email:
|
@@ -327,23 +103,26 @@ files:
|
|
327
103
|
- lib/hoodie/core_ext/hash.rb
|
328
104
|
- lib/hoodie/core_ext/string.rb
|
329
105
|
- lib/hoodie/core_ext/try.rb
|
330
|
-
- lib/hoodie/identity_map.rb
|
331
106
|
- lib/hoodie/inflections.rb
|
332
107
|
- lib/hoodie/inflections/defaults.rb
|
333
108
|
- lib/hoodie/inflections/inflections.rb
|
334
109
|
- lib/hoodie/inflections/rules_collection.rb
|
335
110
|
- lib/hoodie/logging.rb
|
336
|
-
- lib/hoodie/memoizable.rb
|
337
|
-
- lib/hoodie/obfuscate.rb
|
338
|
-
- lib/hoodie/observable.rb
|
339
|
-
- lib/hoodie/os.rb
|
340
|
-
- lib/hoodie/proxy.rb
|
341
|
-
- lib/hoodie/rash.rb
|
342
111
|
- lib/hoodie/stash.rb
|
343
112
|
- lib/hoodie/stash/disk_store.rb
|
344
113
|
- lib/hoodie/stash/mem_store.rb
|
345
|
-
- lib/hoodie/
|
114
|
+
- lib/hoodie/stash/memoizable.rb
|
346
115
|
- lib/hoodie/utils.rb
|
116
|
+
- lib/hoodie/utils/ansi.rb
|
117
|
+
- lib/hoodie/utils/crypto.rb
|
118
|
+
- lib/hoodie/utils/equalizer.rb
|
119
|
+
- lib/hoodie/utils/file_helper.rb
|
120
|
+
- lib/hoodie/utils/konstruktor.rb
|
121
|
+
- lib/hoodie/utils/machine.rb
|
122
|
+
- lib/hoodie/utils/os.rb
|
123
|
+
- lib/hoodie/utils/retry.rb
|
124
|
+
- lib/hoodie/utils/timeout.rb
|
125
|
+
- lib/hoodie/utils/url_helper.rb
|
347
126
|
- lib/hoodie/version.rb
|
348
127
|
homepage: https://github.com/riddopic/hoodie
|
349
128
|
licenses:
|