Skip to content

Commit

Permalink
remove SwiftEither to remove dependency.( use own implemention Result…
Browse files Browse the repository at this point in the history
….swift )
  • Loading branch information
nori0620 committed Jan 10, 2015
1 parent 8accfeb commit 7d36500
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 171 deletions.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Norihiro Sakamoto

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.
6 changes: 2 additions & 4 deletions README.md
@@ -1,9 +1,7 @@
# SwiftPathClass
[![CI Status](http://img.shields.io/travis/nori0620/SwiftFilePath.svg?style=flat)](https://travis-ci.org/nori0620/SwiftFilePath)

# Dependency
* [SwiftEither](https://github.com/gfx/Swift-SwiftEither)
[![CI Status](http://img.shields.io/travis/nori0620/SwiftFilePath.svg?style=flat)](https://travis-ci.org/nori0620/SwiftFilePath)

# LICENSE

The Apache 2.0 License
SwiftPathClass is released under the MIT license. See LICENSE for details.
4 changes: 2 additions & 2 deletions SwiftFilePath.podspec
Expand Up @@ -5,11 +5,11 @@ Pod::Spec.new do |s|
s.version = "0.0.1"
s.summary = "Simple and powerful wrapper for NSFileManager."
s.homepage = "https://github.com/nori0620/SwiftFilePath"
s.license = "Apache License, Version 2.0"
s.license = "MIT"
s.author = { "Norihiro Sakamoto" => "nori0620@gmail.com" }
s.source = { :git => "https://github.com/nori0620/SwiftFilePath.git", :tag => "0.0.1" }
s.platform = :ios, '8.0'
s.source_files = ["SwiftFilePath/**/*.swift", "Vendor/**/*.swift"]
s.source_files = "SwiftFilePath/**/*.swift"
s.requires_arc = true

end
20 changes: 0 additions & 20 deletions SwiftFilePath.xcodeproj/project.pbxproj
Expand Up @@ -13,7 +13,6 @@
CC7833121A610299005E77C3 /* Dir.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC78330F1A610299005E77C3 /* Dir.swift */; };
CC7833131A610299005E77C3 /* Entity.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7833101A610299005E77C3 /* Entity.swift */; };
CC7833141A610299005E77C3 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC7833111A610299005E77C3 /* File.swift */; };
CC78331C1A618186005E77C3 /* Either.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC78331A1A61816B005E77C3 /* Either.swift */; };
CC78331E1A6186B7005E77C3 /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC78331D1A6186B7005E77C3 /* Result.swift */; };
/* End PBXBuildFile section */

Expand All @@ -37,7 +36,6 @@
CC78330F1A610299005E77C3 /* Dir.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dir.swift; sourceTree = "<group>"; };
CC7833101A610299005E77C3 /* Entity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entity.swift; sourceTree = "<group>"; };
CC7833111A610299005E77C3 /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
CC78331A1A61816B005E77C3 /* Either.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = "<group>"; };
CC78331D1A6186B7005E77C3 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -63,7 +61,6 @@
CC7832E21A610124005E77C3 = {
isa = PBXGroup;
children = (
CC7833081A610222005E77C3 /* Vendor */,
CC7832EE1A610124005E77C3 /* SwiftFilePath */,
CC7832FB1A610125005E77C3 /* SwiftFilePathTests */,
CC7832ED1A610124005E77C3 /* Products */,
Expand Down Expand Up @@ -117,22 +114,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
CC7833081A610222005E77C3 /* Vendor */ = {
isa = PBXGroup;
children = (
CC7833171A618046005E77C3 /* SwiftEither-0.0.1 */,
);
path = Vendor;
sourceTree = "<group>";
};
CC7833171A618046005E77C3 /* SwiftEither-0.0.1 */ = {
isa = PBXGroup;
children = (
CC78331A1A61816B005E77C3 /* Either.swift */,
);
path = "SwiftEither-0.0.1";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -240,7 +221,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CC78331C1A618186005E77C3 /* Either.swift in Sources */,
CC78331E1A6186B7005E77C3 /* Result.swift in Sources */,
CC7833141A610299005E77C3 /* File.swift in Sources */,
CC7833121A610299005E77C3 /* Dir.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions SwiftFilePath/Dir.swift
Expand Up @@ -73,9 +73,9 @@ public class Dir: Entity,SequenceType {
return Dir( self.path.stringByAppendingPathComponent(path) )
}

public func mkdir() -> Either<Dir,String> {
public func mkdir() -> Result<Dir,String> {
if( self.exists ){
return Either(failure: "Already exists.<path:\(path)>")
return Result(failure: "Already exists.<path:\(path)>")
}
var error: NSError?
let result = fileManager.createDirectoryAtPath(path,
Expand All @@ -84,8 +84,8 @@ public class Dir: Entity,SequenceType {
error: &error
)
return result
? Either(success: self)
: Either(failure: "Failed to mkdir.< error:\(error?.localizedDescription) path:\(path) >");
? Result(success: self)
: Result(failure: "Failed to mkdir.< error:\(error?.localizedDescription) path:\(path) >");

}

Expand Down
18 changes: 9 additions & 9 deletions SwiftFilePath/Entity.swift
Expand Up @@ -47,35 +47,35 @@ public class Entity {
return path.lastPathComponent
}

public func remove() -> Either<Entity,String> {
public func remove() -> Result<Entity,String> {
assert(self.exists,"To remove file, file MUST be exists")
var error: NSError?
let result = fileManager.removeItemAtPath(path, error:&error)
return result
? Either(success: self)
: Either(failure: "Failed to remove file.<error:\(error?.localizedDescription) path:\(path)>");
? Result(success: self)
: Result(failure: "Failed to remove file.<error:\(error?.localizedDescription) path:\(path)>");
}

public func copyTo(toPath:Entity) -> Either<Entity,String> {
public func copyTo(toPath:Entity) -> Result<Entity,String> {
assert(self.exists,"To copy file, file MUST be exists")
var error: NSError?
let result = fileManager.copyItemAtPath(path,
toPath: toPath.toString,
error: &error)
return result
? Either(success: self)
: Either(failure: "Failed to copy file.<error:\(error?.localizedDescription) from-path:\(path) to-path:\(toPath)>");
? Result(success: self)
: Result(failure: "Failed to copy file.<error:\(error?.localizedDescription) from-path:\(path) to-path:\(toPath)>");
}

public func moveTo(toPath:Entity) -> Either<Entity,String> {
public func moveTo(toPath:Entity) -> Result<Entity,String> {
assert(self.exists,"To move file, file MUST be exists")
var error: NSError?
let result = fileManager.moveItemAtPath(path,
toPath: toPath.toString,
error: &error)
return result
? Either(success: self)
: Either(failure: "Failed to move file.<error:\(error?.localizedDescription) from-path:\(path) to-path:\(toPath)>");
? Result(success: self)
: Result(failure: "Failed to move file.<error:\(error?.localizedDescription) from-path:\(path) to-path:\(toPath)>");
}

private func loadAttributes() -> NSDictionary {
Expand Down
26 changes: 13 additions & 13 deletions SwiftFilePath/File.swift
Expand Up @@ -16,32 +16,32 @@ public class File: Entity {
return Dir( path.stringByDeletingLastPathComponent )
}

public func touch() -> Either<File,String> {
public func touch() -> Result<File,String> {
return self.exists
? self.updateModificationDate()
: self.createEmptyFile()
}

public func updateModificationDate(date: NSDate = NSDate() ) -> Either<File,String>{
public func updateModificationDate(date: NSDate = NSDate() ) -> Result<File,String>{
var error: NSError?
let result = fileManager.setAttributes(
[NSFileModificationDate :date],
ofItemAtPath:path,
error:&error
)
return result
? Either(success: self)
: Either(failure: "Failed to modify file.< error:\(error?.localizedDescription) path:\(path) >");
? Result(success: self)
: Result(failure: "Failed to modify file.< error:\(error?.localizedDescription) path:\(path) >");
}

private func createEmptyFile() -> Either<File,String>{
private func createEmptyFile() -> Result<File,String>{
let result = fileManager.createFileAtPath(path,
contents:NSData(),
attributes:nil
)
return result
? Either(success: self)
: Either(failure: "Failed to create file:\(path)");
? Result(success: self)
: Result(failure: "Failed to create file:\(path)");
}

// MARK: - read/write String
Expand All @@ -59,15 +59,15 @@ public class File: Entity {
return read
}

public func writeString(string:String) -> Either<File,String> {
public func writeString(string:String) -> Result<File,String> {
var error: NSError?
let result = string.writeToFile(path,
atomically:true,
encoding: NSUTF8StringEncoding,
error: &error)
return result
? Either(success: self)
: Either(failure: "Failed to write file.< error:\(error?.localizedDescription) path:\(path) >");
? Result(success: self)
: Result(failure: "Failed to write file.< error:\(error?.localizedDescription) path:\(path) >");
}

// MARK: - read/write NSData
Expand All @@ -76,11 +76,11 @@ public class File: Entity {
return NSData(contentsOfFile: path)
}

public func writeData(data:NSData) -> Either<File,String> {
public func writeData(data:NSData) -> Result<File,String> {
let result = data.writeToFile(path, atomically:true)
return result
? Either(success: self)
: Either(failure: "Failed to write file.< path:\(path) >");
? Result(success: self)
: Result(failure: "Failed to write file.< path:\(path) >");
}

}
23 changes: 0 additions & 23 deletions SwiftFilePathTests/SwiftFilePathTests.swift
Expand Up @@ -21,29 +21,6 @@ extension String {

}

extension Either {

var isSuccess : Bool {
switch self {
case .Success(let success):
return true
case .Failure(let failure):
return false
}
}

var isFailure: Bool {
switch self {
case .Success(let success):
return false
case .Failure(let failure):
return true
}
}

}


// MARK: Test cases

class SwiftFilePathTests: XCTestCase {
Expand Down
96 changes: 0 additions & 96 deletions Vendor/SwiftEither-0.0.1/Either.swift

This file was deleted.

0 comments on commit 7d36500

Please sign in to comment.