Skip to content

Commit

Permalink
(#106) Implementing Folder and fixing Writable ifaces artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
rocket-3 committed Dec 3, 2021
1 parent 9cfbb1e commit fe3f2b6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/main/java/org/fusionsoft/database/folder/FolderOfScalar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/
package org.fusionsoft.database.folder;

import java.nio.file.Path;
import org.cactoos.Scalar;
import org.cactoos.scalar.Unchecked;
import org.fusionsoft.database.Folder;

public class FolderOfScalar implements Folder {

private final Scalar<Path> scalar;

public FolderOfScalar(final Scalar<Path> scalar) {
this.scalar = scalar;
}

@Override
public Path path() {
return new Unchecked<>(this.scalar).value();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The {@link Writable} that represents an iterable of writeables.
* @since 0.1
*/
public class CombinedWritable implements Writable {
public class JoinedWritable implements Writable {

/**
* The Iterable of Writable encapsulated.
Expand All @@ -34,7 +34,7 @@ public class CombinedWritable implements Writable {
* Instantiates a new Combined writable.
* @param writeable The Iterable of Writable to be encapsulated.
*/
public CombinedWritable(final Iterable<Writable> writeable) {
public JoinedWritable(final Iterable<Writable> writeable) {
this.writables = writeable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @since 0.1
* @checkstyle ClassDataAbstractionCouplingCheck (100 lines)
*/
public class SnapshotWritable extends CombinedWritable {
public class SnapshotWritable extends JoinedWritable {

/**
* Instantiates a new Snapshot create procedure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
*/
package org.fusionsoft.database.writable;

import com.amihaiemil.eoyaml.Yaml;
import com.amihaiemil.eoyaml.YamlNode;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.io.WriterTo;
import org.cactoos.scalar.ScalarOf;
import org.cactoos.scalar.Unchecked;
import org.cactoos.text.UncheckedText;
import org.fusionsoft.database.Folder;
import org.fusionsoft.database.SimpleYamlRepresentative;
import org.fusionsoft.database.Writable;
import org.fusionsoft.database.WriteTo;
import org.fusionsoft.database.YamlRepresentative;

/**
Expand Down Expand Up @@ -80,7 +83,18 @@ public WritableYamlDocument(

@Override
public final void writeTo(final Folder folder) {
new WriteTo(this.yaml, folder, this.name).run();
new Unchecked<>(
() -> {
Yaml.createYamlPrinter(
new WriterTo(
folder.path().resolve(
new UncheckedText(this.name).asString()
)
)
).print(this.yaml.asYaml());
return true;
}
).value();
}

}
27 changes: 27 additions & 0 deletions src/main/java/org/fusionsoft/lib/yaml/FileExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2018-2021 FusionSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*/
package org.fusionsoft.lib.yaml;

import org.cactoos.Text;

public class FileExtension implements Text {

@Override
public String asString() {
return "yaml";
}

}

0 comments on commit fe3f2b6

Please sign in to comment.