duration.rb 0.5.2 → 0.6.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 +4 -4
- data/CHANGELOG +13 -0
- data/README.md +6 -2
- data/lib/Duration/Days.rb +1 -4
- data/lib/Duration/Hours.rb +1 -4
- data/lib/Duration/Microseconds.rb +1 -4
- data/lib/Duration/Milliseconds.rb +1 -4
- data/lib/Duration/Minutes.rb +1 -4
- data/lib/Duration/Months.rb +1 -3
- data/lib/Duration/Nanoseconds.rb +1 -3
- data/lib/Duration/Seconds.rb +1 -4
- data/lib/Duration/VERSION.rb +1 -1
- data/lib/Duration/Weeks.rb +1 -4
- data/lib/duration.rb +20 -11
- data/test/loading_test.rb +32 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 879170199d5fdc472851ece21f3896aa08d7767484045d281834255ca51d8c84
|
|
4
|
+
data.tar.gz: a35e1867f9712bb9aa415bcb577434e0683908c9f0c2579dfcaf27476770907c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4ab866878939cd01e8ab62ff977fb53e974fb67b6ea2385c4837f60d2420b73e418ed75ba21aac52143487dd9b6b6c4818a11aac969ce7e14cc403ce7678928
|
|
7
|
+
data.tar.gz: 8b51e85072dbeede9062953fa1391a848242934c0d09559715a66bfc902cbd1284c7e53ef3e6811cbf859611c6f3d746d412eaf1e127e17e619c2a783446d552
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20260812
|
|
4
|
+
|
|
5
|
+
0.6.0: The unit classes are now autoloaded so as to avoid circular loading messages when running the tests. It's faster too!
|
|
6
|
+
|
|
7
|
+
1. + lib/duration.rb: Autoload each unit file, and Common and Relative.
|
|
8
|
+
2. ~ lib/Duration/*.rb: - require_relative './Common', './Relative'
|
|
9
|
+
3. ~ lib/Duration/*.rb: + require_relative '../duration'. Each unit had required both of its neighbours, so that every adjacent pair was a cycle and Ruby warned upon each under -w. The ring was connected besides, so requiring any one unit dragged in eleven files of the thirteen and no part of the gem could be left unread. Requiring one now brings five, and the rest arrive as they are named.
|
|
10
|
+
4. ~ lib/duration.rb: Add a note why VERSION is required and not declared, being the one exception.
|
|
11
|
+
5. ~ README.md: Add a line in the Loading section.
|
|
12
|
+
6. + test/loading_test.rb: that a single unit file required alone still converts, that a unit never named is never read, that one named is, and that the whole loads without warning under -w. Each runs in a process of its own, the test helper having already loaded everything in this one.
|
|
13
|
+
7. ~ Duration::VERSION: /0.5.2/0.6.0/
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## 20260812
|
|
4
17
|
|
|
5
18
|
0.5.2: + gemspec test.
|
data/README.md
CHANGED
|
@@ -52,8 +52,12 @@ require 'duration-numeric' # opt in to the Numeric sugar (5.minutes, etc.),
|
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
The examples below use the `Numeric` sugar, so they assume
|
|
55
|
-
`require 'duration-numeric'`. Without it
|
|
56
|
-
`Duration::Minutes.new(5)` and
|
|
55
|
+
`require 'duration-numeric'`. Without it durations are constructed directly with
|
|
56
|
+
`Duration::Minutes.new(5)` and so on.
|
|
57
|
+
|
|
58
|
+
Either require declares where the unit classes are without reading them. A unit
|
|
59
|
+
file is read when its class is first named, so a program dealing in seconds and
|
|
60
|
+
minutes reads the files for seconds and minutes and leaves the rest unread.
|
|
57
61
|
|
|
58
62
|
## Usage
|
|
59
63
|
|
data/lib/Duration/Days.rb
CHANGED
data/lib/Duration/Hours.rb
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
# Duration/Microseconds.rb
|
|
2
2
|
# Duration::Microseconds
|
|
3
3
|
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative './Relative'
|
|
6
|
-
require_relative './Nanoseconds'
|
|
7
|
-
require_relative './Milliseconds'
|
|
4
|
+
require_relative '../duration'
|
|
8
5
|
|
|
9
6
|
module Duration
|
|
10
7
|
class Microseconds
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
# Duration/Milliseconds.rb
|
|
2
2
|
# Duration::Milliseconds
|
|
3
3
|
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative './Relative'
|
|
6
|
-
require_relative './Microseconds'
|
|
7
|
-
require_relative './Seconds'
|
|
4
|
+
require_relative '../duration'
|
|
8
5
|
|
|
9
6
|
module Duration
|
|
10
7
|
class Milliseconds
|
data/lib/Duration/Minutes.rb
CHANGED
data/lib/Duration/Months.rb
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# Duration/Months.rb
|
|
2
2
|
# Duration::Months
|
|
3
3
|
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative './Relative'
|
|
6
|
-
require_relative './Weeks'
|
|
4
|
+
require_relative '../duration'
|
|
7
5
|
|
|
8
6
|
module Duration
|
|
9
7
|
# A month is not a fixed quantity: its length depends on the calendar. The
|
data/lib/Duration/Nanoseconds.rb
CHANGED
data/lib/Duration/Seconds.rb
CHANGED
data/lib/Duration/VERSION.rb
CHANGED
data/lib/Duration/Weeks.rb
CHANGED
data/lib/duration.rb
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# Duration.rb
|
|
2
2
|
# Duration
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
# Previously, neighbouring units which are used conversion methods used to be requires at the top of each file, so that every adjacent pair was a cycle and Ruby warned upon each under -w.
|
|
5
|
+
|
|
6
|
+
# Now, a unit file is read when its class is first named and not before, which is what lets a program dealing in seconds and minutes loads only Seconds and Minutes, so that units are may easily be left unused.
|
|
7
|
+
|
|
8
|
+
module Duration
|
|
9
|
+
autoload :Common, File.expand_path('Duration/Common', __dir__)
|
|
10
|
+
autoload :Relative, File.expand_path('Duration/Relative', __dir__)
|
|
11
|
+
autoload :Nanoseconds, File.expand_path('Duration/Nanoseconds', __dir__)
|
|
12
|
+
autoload :Microseconds, File.expand_path('Duration/Microseconds', __dir__)
|
|
13
|
+
autoload :Milliseconds, File.expand_path('Duration/Milliseconds', __dir__)
|
|
14
|
+
autoload :Seconds, File.expand_path('Duration/Seconds', __dir__)
|
|
15
|
+
autoload :Minutes, File.expand_path('Duration/Minutes', __dir__)
|
|
16
|
+
autoload :Hours, File.expand_path('Duration/Hours', __dir__)
|
|
17
|
+
autoload :Days, File.expand_path('Duration/Days', __dir__)
|
|
18
|
+
autoload :Weeks, File.expand_path('Duration/Weeks', __dir__)
|
|
19
|
+
autoload :Months, File.expand_path('Duration/Months', __dir__)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# VERSION is required rather than autoloaded, and is the one exception, as there nothing which will load it at runtime.
|
|
23
|
+
|
|
15
24
|
require_relative 'Duration/VERSION'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# test/loading_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative './test_helper'
|
|
4
|
+
|
|
5
|
+
# Each of these wants a process of its own. Within this one the test helper has already loaded the lot, so nothing here could tell a unit which was declared from a unit which was read.
|
|
6
|
+
|
|
7
|
+
describe 'loading' do
|
|
8
|
+
def ruby(source, *flags)
|
|
9
|
+
lib = File.expand_path('../lib', __dir__)
|
|
10
|
+
IO.popen(['ruby', *flags, "-I#{lib}", '-e', source], err: [:child, :out]){|io| io.read}.strip
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "converts when a single unit file is required alone" do
|
|
14
|
+
_(ruby('require "Duration/Seconds"; print Duration::Seconds.new(90).to_minutes.to_f')) \
|
|
15
|
+
.must_equal('1.5')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "does not read a unit which is never named" do
|
|
19
|
+
_(ruby('require "duration.rb"; Duration::Seconds; print $LOADED_FEATURES.grep(/Months/).size')) \
|
|
20
|
+
.must_equal('0')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "reads a unit as soon as it is named" do
|
|
24
|
+
_(ruby('require "duration.rb"; Duration::Months; print $LOADED_FEATURES.grep(/Months/).size')) \
|
|
25
|
+
.must_equal('1')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "loads without warning under -w, no unit requiring another" do
|
|
29
|
+
_(ruby('require "duration.rb"; Duration::Months.new(1).to_nanoseconds; print "ok"', '-w')) \
|
|
30
|
+
.must_equal('ok')
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: duration.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- test/Duration/VERSION_test.rb
|
|
94
94
|
- test/Duration/Weeks_test.rb
|
|
95
95
|
- test/gemspec_test.rb
|
|
96
|
+
- test/loading_test.rb
|
|
96
97
|
- test/test_helper.rb
|
|
97
98
|
homepage: http://github.com/thoran/duration.rb
|
|
98
99
|
licenses:
|