toc_doc 1.8.0 → 1.9.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: 36c32de39cc1eed0396372360e37b86d7df01e342926c32ab03aa450db500ff9
4
- data.tar.gz: 578e0b0c633708c5c8adc7f3e8b0212e563ca7eb07c9e7b73b52d72196b7f652
3
+ metadata.gz: 72ce333b7f46666dc6109150032a053014153937a65f89d629d1a686216d52b3
4
+ data.tar.gz: 064462c8ae43a562a07b5e4f9f36aff3dc1b37f15444f3e912b04b61ce2e506d
5
5
  SHA512:
6
- metadata.gz: b120c55bf6b52c77b78c609867385150647fb0163d32abd449da8a53a4851939f0053caa3983784b80826be6bf4a6097da7084b0580f1d30d63a6066c5c61c7e
7
- data.tar.gz: b463ad3fbc58cbd14101e5d8c1bffa37bacfda4373fd7a5c821ae2666d9b0ce839506e5ca97a2926389398387e900e26aac5cc977e036162d55e497d46de27d1
6
+ metadata.gz: b5750b8a84a14ba7a9144ead48313f8db74829de9f4bddaf58930ebaf1606400dc4cff0a1110cbb587999b22bf0efff490beaa3710fc21c96dbd402d4068c069
7
+ data.tar.gz: 563244b90ad4a8418d7348e88bb1c408955285574a2a5d7efbcac02c9e311b70410f868fbd4777b63a163ce90f525075361ec457b3618537a44ccce133fd33e4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.0] - 2026-04-06
4
+
5
+ ### Added
6
+
7
+ - **`TocDoc::Availability::Collection#availabilities`** — new public method returning all `TocDoc::Availability` instances that have at least one slot; results are memoized and invalidated by `#merge_page!`
8
+ - **`TocDoc::Availability::Collection#all`** — alias for `#availabilities`
9
+ - **`TocDoc::Availability::Collection#slots`** — returns all individual slots across every availability in the collection as `Array<DateTime>`
10
+
11
+ ### Changed
12
+
13
+ - **`TocDoc::Availability::Collection#fetch_next_page`** renamed to **`#load_next!`** for a more idiomatic, mutation-signalling name
14
+
3
15
  ## [1.8.0] - 2026-04-05
4
16
 
5
17
  ### Added
data/README.md CHANGED
@@ -306,10 +306,12 @@ Implements `Enumerable`, yielding `TocDoc::Availability` instances that have at
306
306
  |---|---|---|
307
307
  | `#total` | `Integer` | Total number of available slots across all dates. |
308
308
  | `#next_slot` | `String \| nil` | ISO 8601 datetime of the nearest available slot. `nil` when none remain. |
309
+ | `#availabilities` | `Array<TocDoc::Availability>` | All entries that have at least one slot. Aliased as `#all`. Memoized; invalidated by `#merge_page!`. |
310
+ | `#slots` | `Array<DateTime>` | All individual slots across every availability in the collection. |
309
311
  | `#each` | — | Yields each `TocDoc::Availability` that has at least one slot (excludes empty-slot dates). |
310
312
  | `#raw_availabilities` | `Array<TocDoc::Availability>` | All date entries, including those with no slots. |
311
313
  | `#more?` | `Boolean` | `true` when the API has indicated further pages exist (`next_slot` is present). |
312
- | `#fetch_next_page` | `self` | Fetches the next page and merges it into this collection. Raises `StopIteration` when `#more?` is `false`. Requires a client (i.e. built via `Availability.where`). |
314
+ | `#load_next!` | `self` | Fetches the next window and merges it into this collection. Raises `StopIteration` when `#more?` is `false`. Requires a client (i.e. built via `Availability.where`). |
313
315
  | `#to_h` | `Hash` | Plain-hash representation (only dates with slots in the `availabilities` key). |
314
316
 
315
317
  ### `TocDoc::Availability`
@@ -464,10 +466,10 @@ TocDoc.configure { |c| c.pagination_depth = 3 }
464
466
  # → up to 3 next_slot hops per Availability.where call
465
467
  ```
466
468
 
467
- ### On-demand pagination with `#fetch_next_page`
469
+ ### On-demand pagination with `#load_next!`
468
470
 
469
- After the initial call, check `#more?` and call `#fetch_next_page` to load
470
- additional pages one at a time:
471
+ After the initial call, check `#more?` and call `#load_next!` to load
472
+ additional windows one at a time:
471
473
 
472
474
  ```ruby
473
475
  collection = TocDoc::Availability.where(
@@ -477,7 +479,7 @@ collection = TocDoc::Availability.where(
477
479
  )
478
480
 
479
481
  while collection.more?
480
- collection.fetch_next_page
482
+ collection.load_next!
481
483
  end
482
484
 
483
485
  collection.total # slots across all fetched pages
data/TODO.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [POTENTIAL_ENDPOINTS][POTENTIAL_ENDPOINTS.md]
4
4
 
5
5
 
6
- ## 1.9 — Service Layer rework
6
+ ## Service Layer rework
7
7
 
8
8
  - [ ] `TocDoc::Services::Availabilities` — extract from `Availability.where`
9
9
  - [ ] `TocDoc::Services::Profiles` — extract from `Profile.find`
@@ -12,14 +12,14 @@
12
12
  - [ ] Update top-level shortcuts to delegate to services
13
13
  - [ ] Deprecation on old model-level finders
14
14
 
15
- ## 2.0 — Breaking Changes
15
+ ## Breaking Changes
16
16
 
17
17
  - [ ] Remove deprecated model-level finders
18
18
  - [ ] `Place#coordinates` as `Data.define(:latitude, :longitude)`
19
19
  - [ ] Integration smoke test suite (gated by ENV, weekly CI cron)
20
20
  - [ ] Remove unused HTTP verbs from `Connection` (if auth doesn't ship)
21
21
 
22
- # ???
22
+ # Misc.
23
23
 
24
24
  - [ ] Figure what is `organization_statuses` in the autocomplete endpoint and what to do with it.
25
25
  - [ ] Authentication module
@@ -4,5 +4,5 @@ module TocDoc
4
4
  # The current version of the TocDoc gem.
5
5
  #
6
6
  # @return [String]
7
- VERSION = '1.8.0'
7
+ VERSION = '1.9.0'
8
8
  end
@@ -24,7 +24,7 @@ module TocDoc
24
24
  # @param query [Hash] original query params (used to build next-page requests)
25
25
  # @param path [String] API path for subsequent requests
26
26
  # @param client [TocDoc::Client, nil] client used to fetch additional pages
27
- # via {#fetch_next_page}; +nil+ disables {#fetch_next_page}
27
+ # via {#load_next!}; +nil+ disables {#load_next!}
28
28
  def initialize(data, query: {}, path: '/availabilities.json', client: nil)
29
29
  @data = data.dup
30
30
  @query = query
@@ -32,12 +32,32 @@ module TocDoc
32
32
  @client = client
33
33
  end
34
34
 
35
+ # All {TocDoc::Availability} instances that have at least one slot.
36
+ #
37
+ # Results are memoized and invalidated by {#merge_page!}.
38
+ #
39
+ # @return [Array<TocDoc::Availability>]
40
+ def availabilities
41
+ @availabilities ||= Array(@data['availabilities'])
42
+ .select { |entry| Array(entry['slots']).any? }
43
+ .map { |entry| TocDoc::Availability.new(entry) }
44
+ end
45
+
46
+ alias all availabilities
47
+
48
+ # All individual slots across every availability in the collection.
49
+ #
50
+ # @return [Array<DateTime>]
51
+ def slots
52
+ availabilities.flat_map(&:slots)
53
+ end
54
+
35
55
  # Iterates over {TocDoc::Availability} instances that have at least one slot.
36
56
  #
37
57
  # @yieldparam availability [TocDoc::Availability]
38
58
  # @return [Enumerator] if no block given
39
59
  def each(&)
40
- filtered_entries.each(&)
60
+ availabilities.each(&)
41
61
  end
42
62
 
43
63
  # The total number of available slots in the collection.
@@ -73,7 +93,7 @@ module TocDoc
73
93
  !!@data['next_slot']
74
94
  end
75
95
 
76
- # Fetches the next page of availabilities and merges it into this collection.
96
+ # Fetches the next window of availabilities and merges it into this collection.
77
97
  #
78
98
  # Uses the +next_slot+ date from the API response as the +start_date+ for
79
99
  # the follow-up request.
@@ -83,8 +103,8 @@ module TocDoc
83
103
  # @return [self]
84
104
  #
85
105
  # @example
86
- # collection.fetch_next_page if collection.more?
87
- def fetch_next_page
106
+ # collection.load_next! if collection.more?
107
+ def load_next!
88
108
  raise TocDoc::Error, 'No client available for pagination' unless @client
89
109
  raise StopIteration, 'No more pages available' unless more?
90
110
 
@@ -110,7 +130,7 @@ module TocDoc
110
130
  #
111
131
  # @return [Hash{String => Object}]
112
132
  def to_h
113
- @data.merge('availabilities' => filtered_entries.map(&:to_h))
133
+ @data.merge('availabilities' => availabilities.map(&:to_h))
114
134
  end
115
135
 
116
136
  # Fetches the next window of availabilities (starting the day after the
@@ -121,17 +141,9 @@ module TocDoc
121
141
  def merge_page!(page_data)
122
142
  @data['availabilities'] = @data.fetch('availabilities', []) + page_data.fetch('availabilities', [])
123
143
  @data['total'] = @data.fetch('total', 0) + page_data.fetch('total', 0)
124
- @filtered_entries = nil
144
+ @availabilities = nil
125
145
  self
126
146
  end
127
-
128
- private
129
-
130
- def filtered_entries
131
- @filtered_entries ||= Array(@data['availabilities'])
132
- .select { |entry| Array(entry['slots']).any? }
133
- .map { |entry| TocDoc::Availability.new(entry) }
134
- end
135
147
  end
136
148
  end
137
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toc_doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 01max