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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +7 -5
- data/TODO.md +3 -3
- data/lib/toc_doc/core/version.rb +1 -1
- data/lib/toc_doc/models/availability/collection.rb +27 -15
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72ce333b7f46666dc6109150032a053014153937a65f89d629d1a686216d52b3
|
|
4
|
+
data.tar.gz: 064462c8ae43a562a07b5e4f9f36aff3dc1b37f15444f3e912b04b61ce2e506d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
| `#
|
|
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 `#
|
|
469
|
+
### On-demand pagination with `#load_next!`
|
|
468
470
|
|
|
469
|
-
After the initial call, check `#more?` and call `#
|
|
470
|
-
additional
|
|
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.
|
|
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
|
-
##
|
|
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
|
-
##
|
|
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
|
data/lib/toc_doc/core/version.rb
CHANGED
|
@@ -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 {#
|
|
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
|
-
|
|
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
|
|
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.
|
|
87
|
-
def
|
|
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' =>
|
|
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
|
-
@
|
|
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
|