Skip to content

Commit

Permalink
refactor: Migrate save verb into its own DSL file
Browse files Browse the repository at this point in the history
The `case object save` was previously located into the
`SynonymsDsl.scala` file. However, it was responsible for both synonyms
and rules handling.

This commit moves the entire `case object save` into its own
`SaveDsl.scala` file, like what we already have for existing common verb
such as `get` (`GetDsl.scala`), `list` (`ListDsl.scala`), etc.
  • Loading branch information
aseure committed Jun 20, 2018
1 parent d5d1720 commit 559d25f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/scala/algolia/AlgoliaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import scala.util.matching.Regex
trait AlgoliaDsl
extends Object //Just to have all trait DSL ordered `with`
with KeyDefinitionDsl
with dsl.BatchDsl
with BatchDsl
with BrowseDsl
with ClearDsl
with CopyDsl
Expand All @@ -52,6 +52,7 @@ trait AlgoliaDsl
with MultiQueriesDefinitionDsl
with PartialUpdateObjectDsl
with RulesDsl
with SaveDsl
with SearchDsl
with SynonymsDsl
with WaitForTaskDsl
Expand Down
52 changes: 52 additions & 0 deletions src/main/scala/algolia/dsl/SaveDsl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Algolia
* http://www.algolia.com/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package algolia.dsl

import algolia.definitions._
import algolia.objects.{AbstractSynonym, Rule}
import org.json4s.Formats

trait SaveDsl {

implicit val formats: Formats

object save {

def synonym(synonym: AbstractSynonym) =
SaveSynonymDefinition(synonym = synonym)

def synonyms(synonyms: Iterable[AbstractSynonym]) =
BatchSynonymsDefinition(synonyms = synonyms)

def rule(rule: Rule) =
SaveRuleDefinition(rule = rule)

def rules(rules: Iterable[Rule]) =
BatchRulesDefinition(rules = rules)

}

}
16 changes: 0 additions & 16 deletions src/main/scala/algolia/dsl/SynonymsDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ trait SynonymsDsl {

implicit val formats: Formats

object save {

def synonym(synonym: AbstractSynonym) =
SaveSynonymDefinition(synonym = synonym)

def synonyms(synonyms: Iterable[AbstractSynonym]) =
BatchSynonymsDefinition(synonyms = synonyms)

def rule(rule: Rule) =
SaveRuleDefinition(rule = rule)

def rules(rules: Iterable[Rule]) =
BatchRulesDefinition(rules = rules)

}

implicit object GetSynonymDefinitionExecutable
extends Executable[GetSynonymDefinition, AbstractSynonym] {

Expand Down

0 comments on commit 559d25f

Please sign in to comment.