blinkbox-common_helpers 0.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 +15 -0
- data/CHANGELOG.md +14 -0
- data/README.md +31 -0
- data/VERSION +1 -0
- data/lib/blinkbox/tictoc.rb +60 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzdmOWVmNTZhNWM2ZTkzNzEyZGY5YTUxOTY2MjUwN2Q3NmQwM2JjZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTkzYTEwNjJmYWVlMDRhYzZjZDI2YWMzYThiMDYwZTQ5MDk2NmZiOQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGU1ZWNkNTFjY2JiNGZkZGUwN2RmODFhODIxYTc3ZTkxMzVlZDU0NmUxOGIy
|
10
|
+
YjJlOTUwNTQ5MTBmZTNkMjNiYjY1Y2Q3NGM2YTU3ZTI5YmY3MGIwOWM0OTcz
|
11
|
+
ZTI3YmUwYWZiZDRiMWU5ODg3MDA2YjJkMGQwYmUxMjc0NTMyZTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2U1ZjM1YjkyNmQwYzY1NmJmOTY4MjA0MzFmOTQ5NGIxNGZjMTlmMzhjZTNl
|
14
|
+
NWU0YmI3YzNkMmU1MmI2OTlmOTAzODA3NDVlNTM0ZGUxZjY1ZWFmNjNjMWM3
|
15
|
+
OWIwMDU2Mjk5OTljMTc3ODcyMzExODZjMzY2MTc2Njg1OGVlZjU=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## Open Source release (2015-01-28 14:11:21)
|
4
|
+
|
5
|
+
Today we have decided to publish parts of our codebase on Github under the [MIT licence](LICENCE). The licence is very permissive, but we will always appreciate hearing if and where our work is used!
|
6
|
+
|
7
|
+
## 0.1.0 ([#1](https://git.mobcastdev.com/Platform/common_helpers.rb/pull/1) 2014-10-07 07:55:34)
|
8
|
+
|
9
|
+
Tictoc
|
10
|
+
|
11
|
+
### New Feature
|
12
|
+
|
13
|
+
- Added `tic`, `toc` and `reset_tictoc` in the `Blinkbox::CommonHelpers::TicToc` library for counting timespans.
|
14
|
+
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Blinkbox::CommonHelpers
|
2
|
+
|
3
|
+
A bunch of helpful snippets of Ruby.
|
4
|
+
|
5
|
+
## TicToc
|
6
|
+
|
7
|
+
Track how long things took in your app:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
include Blinkbox::CommonHelpers::TicToc
|
11
|
+
tic
|
12
|
+
sleep 9
|
13
|
+
p toc
|
14
|
+
# => 9001
|
15
|
+
# (It is over 9000 because time is an illusion, lunchtime doubly so)
|
16
|
+
```
|
17
|
+
|
18
|
+
You can also track timespans in parallel:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
include Blinkbox::CommonHelpers::TicToc
|
22
|
+
tic :a
|
23
|
+
sleep 1
|
24
|
+
tic :b
|
25
|
+
sleep 1
|
26
|
+
p toc :b
|
27
|
+
# => 1000
|
28
|
+
sleep 1
|
29
|
+
p toc :a
|
30
|
+
# => 3000
|
31
|
+
```
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Blinkbox
|
2
|
+
module CommonHelpers
|
3
|
+
# Gives you two methods, `tic` and `toc`. Without arguments `toc` will give you the number of milliseconds
|
4
|
+
# since you last called `tic`. Takes one argument, which can be used to have two timers running independently:
|
5
|
+
#
|
6
|
+
# @example: Basic use
|
7
|
+
# include Blinkbox::CommonHelpers::TicToc
|
8
|
+
# tic
|
9
|
+
# sleep 9
|
10
|
+
# p toc
|
11
|
+
# # => 9001
|
12
|
+
# # (It is over 9000 because time is an illusion, lunchtime doubly so)
|
13
|
+
#
|
14
|
+
# @example: Parallel use
|
15
|
+
# include Blinkbox::CommonHelpers::TicToc
|
16
|
+
# tic :a
|
17
|
+
# sleep 1
|
18
|
+
# tic :b
|
19
|
+
# sleep 1
|
20
|
+
# p toc :b
|
21
|
+
# # => 1000
|
22
|
+
# sleep 1
|
23
|
+
# p toc :a
|
24
|
+
# # => 3000
|
25
|
+
module TicToc
|
26
|
+
# Starts a timer with the given label. Will return the last value of the timer
|
27
|
+
# if #tic had been called before.
|
28
|
+
#
|
29
|
+
# @param [Symbol] label The label to use.
|
30
|
+
# @return [Time, nil] The Time #tic was called with this label previously
|
31
|
+
def tic(label = :default)
|
32
|
+
last_value = (@@timers ||= {})[label]
|
33
|
+
@@timers[label] = Time.now.utc
|
34
|
+
last_value
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the number of milliseconds since tic (for the same label) was called.
|
38
|
+
# Will return nil if tic has never been called.
|
39
|
+
#
|
40
|
+
# @param [Symbol] label The label to use.
|
41
|
+
# @return [Float, nil] The number of milliseconds since the equivalent #tic was last called.
|
42
|
+
def toc(label = :default)
|
43
|
+
return nil if @@timers[label].nil?
|
44
|
+
((Time.now.utc - @@timers[label]) * 1000).to_f
|
45
|
+
end
|
46
|
+
|
47
|
+
# Resets the timer for a specific label, or all labels (if none are specified)
|
48
|
+
#
|
49
|
+
# @param [Array<Symbol>] labels The labels to reset
|
50
|
+
# @return [nil]
|
51
|
+
def tictoc_reset(labels = [])
|
52
|
+
@@timers = {} if labels.empty?
|
53
|
+
labels.each do |label|
|
54
|
+
@@timers[label] = nil
|
55
|
+
end
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blinkbox-common_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JP Hastings-Spital
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-mocks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Extensions to ruby useful for blinkbox Books
|
70
|
+
email:
|
71
|
+
- jphastings@blinkbox.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- CHANGELOG.md
|
77
|
+
files:
|
78
|
+
- CHANGELOG.md
|
79
|
+
- README.md
|
80
|
+
- VERSION
|
81
|
+
- lib/blinkbox/tictoc.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Extensions to ruby useful for blinkbox Books
|
105
|
+
test_files: []
|