Skip to content

Commit eeb1406

Browse files
authored
Merge pull request #2 from Runabout-LLC/dev
v1.0.0
2 parents 9013960 + 4eaa421 commit eeb1406

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## 1.0.0 - 2024-02-26
4+
Official release
5+
6+
### Added
7+
- Added datetime field to the Runabout json object.
8+
- Added a setter to the RunaboutServiceBuilder to provide custom datetime suppliers.
9+
10+
## 0.0.2 - 2024-02-25
11+
### Changed
12+
- Changed the dependencies portion of the Runabout to be a Set of Strings representing the fully qualified class names of the dependencies.
13+
14+
## 0.0.1 - 2024-02-25
15+
Initial release of the runabout-java library.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = 'dev.runabout'
10-
version = '0.0.2'
10+
version = '1.0.0'
1111

1212
repositories {
1313
mavenCentral()

src/main/java/dev/runabout/RunaboutConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ private RunaboutConstants() {
1212
public static final String EVAL_KEY = "eval";
1313
public static final String DEPENDENCIES_KEY = "dependencies";
1414
public static final String INPUTS_KEY = "inputs";
15+
public static final String DATETIME_KEY = "datetime";
1516
}

src/main/java/dev/runabout/RunaboutServiceBuilder.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.runabout;
22

33
import java.lang.reflect.Method;
4+
import java.time.Instant;
45
import java.util.Objects;
56
import java.util.Optional;
67
import java.util.Set;
@@ -14,11 +15,12 @@
1415
*/
1516
public class RunaboutServiceBuilder<T extends JsonObject> {
1617

18+
private boolean excludeSuper = false;
1719
private Supplier<Method> callerSupplier;
1820
private Set<Class<?>> callerClassBlacklist;
1921
private RunaboutSerializer customSerializer;
2022
private Consumer<Throwable> throwableConsumer;
21-
private boolean excludeSuper = false;
23+
private Supplier<String> datetimeSupplier;
2224

2325
private final Supplier<T> jsonFactory;
2426

@@ -109,6 +111,20 @@ public RunaboutServiceBuilder<T> setExcludeSuper(boolean excludeSuper) {
109111
this.excludeSuper = excludeSuper;
110112
return this;
111113
}
114+
115+
/**
116+
* Sets the datetime supplier for the RunaboutService.
117+
* The supplier should return the current datetime UTC as an ISO-8601 formatted string.
118+
* By default, the supplier will return the current datetime using {@link Instant#now()}.
119+
*
120+
* @param datetimeSupplier The datetime supplier.
121+
* @return The RunaboutServiceBuilder.
122+
*/
123+
public RunaboutServiceBuilder<T> setDatetimeSupplier(Supplier<String> datetimeSupplier) {
124+
this.datetimeSupplier = datetimeSupplier;
125+
return this;
126+
}
127+
112128
/**
113129
* Builds the RunaboutService.
114130
*
@@ -130,8 +146,11 @@ public RunaboutService<T> build() {
130146
final Consumer<Throwable> throwableConsumerFinal = Optional.ofNullable(throwableConsumer)
131147
.orElse(RunaboutServiceBuilder::defaultThrowableConsumer);
132148

149+
final Supplier<String> datetimeSupplier = Optional.ofNullable(this.datetimeSupplier)
150+
.orElseGet(() -> () -> Instant.now().toString());
151+
133152
return new RunaboutServiceImpl<>(excludeSuper, throwableConsumerFinal, callerSupplierFinal,
134-
customSerializerFinal, jsonFactory);
153+
customSerializerFinal, jsonFactory, datetimeSupplier);
135154
}
136155

137156
private static void defaultThrowableConsumer(Throwable t) {

src/main/java/dev/runabout/RunaboutServiceImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ class RunaboutServiceImpl<T extends JsonObject> implements RunaboutService<T> {
1919
private final Supplier<Method> callerSupplier;
2020
private final RunaboutSerializer customSerializer;
2121
private final Supplier<T> jsonFactory;
22+
private final Supplier<String> datetimeSupplier;
2223

2324
private final DefaultSerializer defaultSerializer = DefaultSerializer.getInstance();
2425

2526
RunaboutServiceImpl(boolean excludeSuper, Consumer<Throwable> throwableConsumer, Supplier<Method> callerSupplier,
26-
RunaboutSerializer customSerializer, Supplier<T> jsonFactory) {
27+
RunaboutSerializer customSerializer, Supplier<T> jsonFactory,
28+
Supplier<String> datetimeSupplier) {
2729
this.throwableConsumer = throwableConsumer;
2830
this.excludeSuper = excludeSuper;
2931
this.callerSupplier = callerSupplier;
3032
this.customSerializer = customSerializer;
3133
this.jsonFactory = jsonFactory;
34+
this.datetimeSupplier = datetimeSupplier;
3235
}
3336

3437
@Override
@@ -72,6 +75,9 @@ public T toRunaboutJson(Method method, Object... objects) {
7275
// Put method data in json.
7376
json.put(RunaboutConstants.METHOD_KEY, method.toString());
7477

78+
// Put datetime data in json.
79+
json.put(RunaboutConstants.DATETIME_KEY, datetimeSupplier.get());
80+
7581
final List<JsonObject> inputs = new ArrayList<>();
7682
for (final Object object: objects) {
7783
final RunaboutInput input = serialize(object);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
JSON_CONTRACT_VERSION=1.0.0
1+
JSON_CONTRACT_VERSION=1.1.0

0 commit comments

Comments
 (0)