Skip to content

Commit

Permalink
add support for creating views directly from Shoebox
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Apr 22, 2017
1 parent 748fe30 commit cd94593
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.github.sanity'
version '0.2.7'
version '0.2.8'

buildscript {
ext.kotlin_version = '1.1.1'
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/com/github/sanity/shoebox/Shoebox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ class Shoebox<T : Any>(val store: Store<T>, private val kc: KClass<T>) {
}
}


fun view(name : String, by : (T) -> String) : View<T> {
val store = when (store) {
is MemoryStore<T> -> MemoryStore<View.Reference>()
is DirectoryStore<T> ->
DirectoryStore<View.Reference>(store.directory.parent.resolve("${store.directory.fileName.toString()}-$name-view"))
else -> throw RuntimeException("Shoebox doesn't currently support creating a view for store type ${store::class.simpleName}")
}
return View<T>(Shoebox(store), this, View.VerifyBehavior.ASYNC_VERIFY, by)
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/github/sanity/shoebox/Store.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package com.github.sanity.shoebox
*/
interface Store<T> {
val entries: Iterable<KeyValue<T>>

fun remove(key: String): T?
operator fun get(key: String): T?
operator fun set(key: String, value: T) : T?
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/github/sanity/shoebox/View.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.sanity.shoebox

import java.nio.file.Path
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.concurrent.thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlin.reflect.KClass

inline fun <reified T : Any> DirectoryStore(directory : Path) = DirectoryStore(directory, T::class)

class DirectoryStore<T : Any>(private val directory : Path, private val kc : KClass<T>) : Store<T> {
class DirectoryStore<T : Any>(val directory : Path, private val kc : KClass<T>) : Store<T> {
companion object {
const private val LOCK_FILENAME = "shoebox.lock"
const private val LOCK_TOUCH_TIME_MS = 2000.toLong()
Expand Down

0 comments on commit cd94593

Please sign in to comment.