From 7d3650098cf8810d3a5e424a04eb21ceb9db1824 Mon Sep 17 00:00:00 2001 From: Norihiro Sakamoto Date: Sun, 11 Jan 2015 02:18:35 +0900 Subject: [PATCH] remove SwiftEither to remove dependency.( use own implemention Result.swift ) --- LICENSE | 21 +++++ README.md | 6 +- SwiftFilePath.podspec | 4 +- SwiftFilePath.xcodeproj/project.pbxproj | 20 ----- SwiftFilePath/Dir.swift | 8 +- SwiftFilePath/Entity.swift | 18 ++-- SwiftFilePath/File.swift | 26 +++--- SwiftFilePathTests/SwiftFilePathTests.swift | 23 ----- Vendor/SwiftEither-0.0.1/Either.swift | 96 --------------------- 9 files changed, 51 insertions(+), 171 deletions(-) create mode 100644 LICENSE delete mode 100644 Vendor/SwiftEither-0.0.1/Either.swift diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..adbcda4 --- /dev/null +++ b/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. diff --git a/README.md b/README.md index 1ec3af8..975fb0e 100644 --- a/README.md +++ b/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. diff --git a/SwiftFilePath.podspec b/SwiftFilePath.podspec index 058f169..63a087f 100644 --- a/SwiftFilePath.podspec +++ b/SwiftFilePath.podspec @@ -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 diff --git a/SwiftFilePath.xcodeproj/project.pbxproj b/SwiftFilePath.xcodeproj/project.pbxproj index d7c197b..9c13b98 100644 --- a/SwiftFilePath.xcodeproj/project.pbxproj +++ b/SwiftFilePath.xcodeproj/project.pbxproj @@ -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 */ @@ -37,7 +36,6 @@ CC78330F1A610299005E77C3 /* Dir.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dir.swift; sourceTree = ""; }; CC7833101A610299005E77C3 /* Entity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entity.swift; sourceTree = ""; }; CC7833111A610299005E77C3 /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; - CC78331A1A61816B005E77C3 /* Either.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Either.swift; sourceTree = ""; }; CC78331D1A6186B7005E77C3 /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -63,7 +61,6 @@ CC7832E21A610124005E77C3 = { isa = PBXGroup; children = ( - CC7833081A610222005E77C3 /* Vendor */, CC7832EE1A610124005E77C3 /* SwiftFilePath */, CC7832FB1A610125005E77C3 /* SwiftFilePathTests */, CC7832ED1A610124005E77C3 /* Products */, @@ -117,22 +114,6 @@ name = "Supporting Files"; sourceTree = ""; }; - CC7833081A610222005E77C3 /* Vendor */ = { - isa = PBXGroup; - children = ( - CC7833171A618046005E77C3 /* SwiftEither-0.0.1 */, - ); - path = Vendor; - sourceTree = ""; - }; - CC7833171A618046005E77C3 /* SwiftEither-0.0.1 */ = { - isa = PBXGroup; - children = ( - CC78331A1A61816B005E77C3 /* Either.swift */, - ); - path = "SwiftEither-0.0.1"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -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 */, diff --git a/SwiftFilePath/Dir.swift b/SwiftFilePath/Dir.swift index e88cac4..3544d3c 100644 --- a/SwiftFilePath/Dir.swift +++ b/SwiftFilePath/Dir.swift @@ -73,9 +73,9 @@ public class Dir: Entity,SequenceType { return Dir( self.path.stringByAppendingPathComponent(path) ) } - public func mkdir() -> Either { + public func mkdir() -> Result { if( self.exists ){ - return Either(failure: "Already exists.") + return Result(failure: "Already exists.") } var error: NSError? let result = fileManager.createDirectoryAtPath(path, @@ -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) >"); } diff --git a/SwiftFilePath/Entity.swift b/SwiftFilePath/Entity.swift index b23df74..1664867 100644 --- a/SwiftFilePath/Entity.swift +++ b/SwiftFilePath/Entity.swift @@ -47,35 +47,35 @@ public class Entity { return path.lastPathComponent } - public func remove() -> Either { + public func remove() -> Result { 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."); + ? Result(success: self) + : Result(failure: "Failed to remove file."); } - public func copyTo(toPath:Entity) -> Either { + public func copyTo(toPath:Entity) -> Result { 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."); + ? Result(success: self) + : Result(failure: "Failed to copy file."); } - public func moveTo(toPath:Entity) -> Either { + public func moveTo(toPath:Entity) -> Result { 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."); + ? Result(success: self) + : Result(failure: "Failed to move file."); } private func loadAttributes() -> NSDictionary { diff --git a/SwiftFilePath/File.swift b/SwiftFilePath/File.swift index 9485f7e..679f19e 100644 --- a/SwiftFilePath/File.swift +++ b/SwiftFilePath/File.swift @@ -16,13 +16,13 @@ public class File: Entity { return Dir( path.stringByDeletingLastPathComponent ) } - public func touch() -> Either { + public func touch() -> Result { return self.exists ? self.updateModificationDate() : self.createEmptyFile() } - public func updateModificationDate(date: NSDate = NSDate() ) -> Either{ + public func updateModificationDate(date: NSDate = NSDate() ) -> Result{ var error: NSError? let result = fileManager.setAttributes( [NSFileModificationDate :date], @@ -30,18 +30,18 @@ public class File: Entity { 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{ + private func createEmptyFile() -> Result{ 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 @@ -59,15 +59,15 @@ public class File: Entity { return read } - public func writeString(string:String) -> Either { + public func writeString(string:String) -> Result { 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 @@ -76,11 +76,11 @@ public class File: Entity { return NSData(contentsOfFile: path) } - public func writeData(data:NSData) -> Either { + public func writeData(data:NSData) -> Result { 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) >"); } } diff --git a/SwiftFilePathTests/SwiftFilePathTests.swift b/SwiftFilePathTests/SwiftFilePathTests.swift index 666b80e..f5a2ba3 100644 --- a/SwiftFilePathTests/SwiftFilePathTests.swift +++ b/SwiftFilePathTests/SwiftFilePathTests.swift @@ -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 { diff --git a/Vendor/SwiftEither-0.0.1/Either.swift b/Vendor/SwiftEither-0.0.1/Either.swift deleted file mode 100644 index 4011324..0000000 --- a/Vendor/SwiftEither-0.0.1/Either.swift +++ /dev/null @@ -1,96 +0,0 @@ -// -// Either.swift -// SwiftEither -// -// Created by Fuji Goro on 2014/12/31. -// Copyright (c) 2014年 FUJI Goro. All rights reserved. -// - -/// Represent either Success or Failure, implementiong the Either pattern -public enum Either { - typealias Left = S - typealias Right = F - - case Success(EitherContainer) - case Failure(EitherContainer) - - public init(success: S) { - self = .Success(EitherContainer(success)) - } - public init(failure: F) { - self = .Failure(EitherContainer(failure)) - } - - /// Evaluates the argument block with the receiver's success value if the receiver is in "success" state. - /// Returns the failure value of the receiver otherwise. - public func chain(f: (S) -> Either) -> Either { - switch self { - case .Success(let s): - return f(s.value) - case .Failure(let e): - return Either.Failure(e) - } - } - - /// Returns the receiver itself if the receiver is in "success" state. - /// Evaluates the argument block otherwise. - public func fallback(f: () -> Either) -> Either { - switch self { - case .Success: - return self - case .Failure: - return f() - } - } - - public var successValue: S? { - switch self { - case .Success(let s): - return s.value - case .Failure(let f): - return nil - } - } - - public var failureValue: F? { - switch self { - case .Success(let s): - return nil - case .Failure(let f): - return f.value - } - } -} - -extension Either: Printable { - public var description: String { - switch self { - case .Success(let s): - return "Either(success: \(s.value))" - case .Failure(let f): - return "Either(failure: \(f.value))" - } - } -} - -/// A reference type that has a value type -public class EitherContainer { - public let value: T - - internal init(_ value: T) { - self.value = value - } -} - -/// The fallback operator, alike to null coalescing operator, executes right-hand side expression -/// if left-hand side is in failure state. -/// This is the same as left.fallback(right). -public func ??(left: Either, right: @autoclosure () -> Either) -> Either { - return left.fallback(right) -} - -public func ??(left: Either, right: @autoclosure () -> S) -> Either { - return left.fallback({ - return Either(success: right()) - }) -}