Skip to content

Commit

Permalink
Convert one-line methods (i.e. almost everything) to expression bodie…
Browse files Browse the repository at this point in the history
…s, to be more idiomatic.

Also removed incorrect `@throws` from documentation
  • Loading branch information
jnizet committed Jun 4, 2016
1 parent 0e27c24 commit 9a4cf96
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ import com.ninja_squad.dbsetup.DbSetupTracker
*
* @author JB Nizet
*/
fun DbSetup.launchWith(tracker: DbSetupTracker) {
tracker.launchIfNecessary(this)
}
fun DbSetup.launchWith(tracker: DbSetupTracker) = tracker.launchIfNecessary(this)
Original file line number Diff line number Diff line change
Expand Up @@ -70,90 +70,65 @@ class DbSetupBuilder(private val to: Destination, var binderConfiguration: Binde
* Adds a DeleteAll operation to the DbSetup
* @param table the table to delete from
*/
fun deleteAllFrom(table: String) {
execute(Operations.deleteAllFrom(table))
}
fun deleteAllFrom(table: String) = execute(Operations.deleteAllFrom(table))

/**
* Adds DeleteAll operations to the DbSetup
* @param tables the tables to delete from
*/
fun deleteAllFrom(vararg tables: String) {
execute(Operations.deleteAllFrom(*tables))
}
fun deleteAllFrom(vararg tables: String) = execute(Operations.deleteAllFrom(*tables))

/**
* Adds DeleteAll operations to the DbSetup
* @param tables the tables to delete from
*/
fun deleteAllFrom(tables: List<String>) {
execute(Operations.deleteAllFrom(tables))
}
fun deleteAllFrom(tables: List<String>) = execute(Operations.deleteAllFrom(tables))

/**
* Adds a Truncate operation to the DbSetup
* @param table the table to truncate
*/
fun truncate(table: String) {
execute(Operations.truncate(table))
}
fun truncate(table: String) = execute(Operations.truncate(table))

/**
* Adds Truncate operations to the DbSetup
* @param tables the tables to delete from
*/
fun truncate(vararg tables: String) {
execute(Operations.truncate(*tables))
}
fun truncate(vararg tables: String) = execute(Operations.truncate(*tables))

/**
* Adds Truncate operations to the DbSetup
* @param tables the tables to truncate
*/
fun truncate(tables: List<String>) {
execute(Operations.truncate(tables))
}
fun truncate(tables: List<String>) = execute(Operations.truncate(tables))

/**
* Adds a SqlOperation to the DbSetup
* @param statement the SQL statement to execute
*/
fun sql(statement: String) {
execute(Operations.sql(statement))
}
fun sql(statement: String) = execute(Operations.sql(statement))

/**
* Adds SqlOperations to the DbSetup
* @param statements the SQL statements to execute
*/
fun sql(vararg statements: String) {
execute(Operations.sql(*statements))
}
fun sql(vararg statements: String) = execute(Operations.sql(*statements))

/**
* Adds SqlOperations to the DbSetup
* @param statements the SQL statements to execute
*/
fun sql(statements: List<String>) {
execute(Operations.sql(statements))
}
fun sql(statements: List<String>) = execute(Operations.sql(statements))

/**
* Adds an operation to the DbSetup. Custom extension functions typically delegate to this method to
* add the operation they want.
* @param operation the operation to add
*/
fun execute(operation: Operation) {
operations.add(operation)
}
fun execute(operation: Operation) = operations.add(operation)

/**
* Builds the DbSetup. This method is called by the dbSetup function after the builder has been configured.
* @throws IllegalStateException if the destination has not been set
*/
internal fun build(): DbSetup {
return DbSetup(to,
Operations.sequenceOf(operations),
binderConfiguration)
}
internal fun build() = DbSetup(to, Operations.sequenceOf(operations), binderConfiguration)
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,4 @@ fun Insert.Builder.mappedValues(vararg entries: Pair<String, Any?>): Insert.Buil
*
* @author JB Nizet
*/
fun Insert.Builder.repeatingMappedValues(vararg entries: Pair<String, Any?>): Insert.RowRepeater {
return this.repeatingValues(mapOf(*entries))
}
fun Insert.Builder.repeatingMappedValues(vararg entries: Pair<String, Any?>) = this.repeatingValues(mapOf(*entries))

0 comments on commit 9a4cf96

Please sign in to comment.