duration.rb 0.5.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6ba0b1a782117f5c6f5b7798620456110e617f5cf2f59ccedd45845cab01674
4
- data.tar.gz: aa225e9b5369e6f334fc0a0962e57cb64c5a6ead3008d91fcbc74448c91fba2e
3
+ metadata.gz: 879170199d5fdc472851ece21f3896aa08d7767484045d281834255ca51d8c84
4
+ data.tar.gz: a35e1867f9712bb9aa415bcb577434e0683908c9f0c2579dfcaf27476770907c
5
5
  SHA512:
6
- metadata.gz: '045846aba621660eabc73c4115457a15e5f3838a0ba8fcced57fa5381c20ce68cc73ea64b51c2acf1d5bfbe7efc3c36c4854c41f019e9d156eb2687826ad4a4a'
7
- data.tar.gz: d0f3455bd9631c7f423151f3aa14fc1a0b4f9bca264a4fe83ad56e535404e4d48b246af457814d5077f429ccfcc064b3f376d9bf649995fe1abff71301d9a349
6
+ metadata.gz: b4ab866878939cd01e8ab62ff977fb53e974fb67b6ea2385c4837f60d2420b73e418ed75ba21aac52143487dd9b6b6c4818a11aac969ce7e14cc403ce7678928
7
+ data.tar.gz: 8b51e85072dbeede9062953fa1391a848242934c0d09559715a66bfc902cbd1284c7e53ef3e6811cbf859611c6f3d746d412eaf1e127e17e619c2a783446d552
data/CHANGELOG CHANGED
@@ -1,5 +1,27 @@
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
+
16
+ ## 20260812
17
+
18
+ 0.5.2: + gemspec test.
19
+
20
+ 1. + test/gemspec_test.rb: Ensure that the specification validates, that no date is pinned, that the version comes from Duration::VERSION, and that the runtime and development dependencies are those expected.
21
+ 2. ~ duration.rb.gemspec: /a description identical to the summary/a description of its own/. Found by the test above upon its first run, spec.validate having warned of it. The summary says what the gem is; the description now says how it goes about it.
22
+ 3. ~ Duration::VERSION: /0.5.1/0.5.2/
23
+
24
+
3
25
  ## 20260812
4
26
 
5
27
  0.5.1: + VERSION 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, construct durations directly with
56
- `Duration::Minutes.new(5)` and friends.
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/duration.rb.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.version = Duration::VERSION
12
12
 
13
13
  spec.summary = "Objects for handling durations of time."
14
- spec.description = "Objects for handling durations of time."
14
+ spec.description = "The unit is the class rather than a decoration upon a number of seconds, so a Minutes holds minutes and no unit is privileged as a base. Nothing is normalised at construction and conversions divide by exact ratios, so an Integer or a Rational stays exact the whole way through, with to_f left for the edge."
15
15
 
16
16
  spec.author = 'thoran'
17
17
  spec.email = 'code@thoran.com'
data/lib/Duration/Days.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  # Duration/Days.rb
2
2
  # Duration::Days
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Hours'
7
- require_relative './Weeks'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Days
@@ -1,10 +1,7 @@
1
1
  # Duration/Hours.rb
2
2
  # Duration::Hours
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Minutes'
7
- require_relative './Days'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Hours
@@ -1,10 +1,7 @@
1
1
  # Duration/Microseconds.rb
2
2
  # Duration::Microseconds
3
3
 
4
- require_relative './Common'
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 './Common'
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
@@ -1,10 +1,7 @@
1
1
  # Duration/Minutes.rb
2
2
  # Duration::Minutes
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Seconds'
7
- require_relative './Hours'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Minutes
@@ -1,9 +1,7 @@
1
1
  # Duration/Months.rb
2
2
  # Duration::Months
3
3
 
4
- require_relative './Common'
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
@@ -1,9 +1,7 @@
1
1
  # Duration/Nanoseconds.rb
2
2
  # Duration::Nanoseconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Microseconds'
4
+ require_relative '../duration'
7
5
 
8
6
  module Duration
9
7
  class Nanoseconds
@@ -1,10 +1,7 @@
1
1
  # Duration/Seconds.rb
2
2
  # Duration::Seconds
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Milliseconds'
7
- require_relative './Minutes'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Seconds
@@ -1,3 +1,3 @@
1
1
  module Duration
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -1,10 +1,7 @@
1
1
  # Duration/Weeks.rb
2
2
  # Duration::Weeks
3
3
 
4
- require_relative './Common'
5
- require_relative './Relative'
6
- require_relative './Days'
7
- require_relative './Months'
4
+ require_relative '../duration'
8
5
 
9
6
  module Duration
10
7
  class Weeks
data/lib/duration.rb CHANGED
@@ -1,15 +1,24 @@
1
1
  # Duration.rb
2
2
  # Duration
3
3
 
4
- module Duration; end
5
-
6
- require_relative 'Duration/Nanoseconds'
7
- require_relative 'Duration/Microseconds'
8
- require_relative 'Duration/Milliseconds'
9
- require_relative 'Duration/Seconds'
10
- require_relative 'Duration/Minutes'
11
- require_relative 'Duration/Hours'
12
- require_relative 'Duration/Days'
13
- require_relative 'Duration/Weeks'
14
- require_relative 'Duration/Months'
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,27 @@
1
+ # test/gemspec_test.rb
2
+
3
+ require_relative './test_helper'
4
+
5
+ describe 'duration.rb.gemspec' do
6
+ let(:spec){Gem::Specification.load(File.expand_path('../duration.rb.gemspec', __dir__))}
7
+
8
+ it "is a valid specification" do
9
+ _(spec.validate).must_equal(true)
10
+ end
11
+
12
+ it "does not pin a date" do
13
+ _(spec.date).must_equal(Gem::Specification.new.date)
14
+ end
15
+
16
+ it "takes its version from Duration::VERSION" do
17
+ _(spec.version.to_s).must_equal(Duration::VERSION)
18
+ end
19
+
20
+ it "declares no runtime dependencies" do
21
+ _(spec.runtime_dependencies.map(&:name).sort).must_equal([])
22
+ end
23
+
24
+ it "declares its development dependencies" do
25
+ _(spec.development_dependencies.map(&:name).sort).must_equal(%w{minitest minitest-spec-context rake})
26
+ end
27
+ end
@@ -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.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -51,7 +51,10 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- description: Objects for handling durations of time.
54
+ description: The unit is the class rather than a decoration upon a number of seconds,
55
+ so a Minutes holds minutes and no unit is privileged as a base. Nothing is normalised
56
+ at construction and conversions divide by exact ratios, so an Integer or a Rational
57
+ stays exact the whole way through, with to_f left for the edge.
55
58
  email: code@thoran.com
56
59
  executables: []
57
60
  extensions: []
@@ -89,6 +92,8 @@ files:
89
92
  - test/Duration/Seconds_test.rb
90
93
  - test/Duration/VERSION_test.rb
91
94
  - test/Duration/Weeks_test.rb
95
+ - test/gemspec_test.rb
96
+ - test/loading_test.rb
92
97
  - test/test_helper.rb
93
98
  homepage: http://github.com/thoran/duration.rb
94
99
  licenses: